In Python, there has only an object data type for all global variables. No matter that is a string or number, a python programmer does not need to declare the data type of that variable before using it because each variable in Python is an object variable.
# Python identifier is a name used to identify a variable decimal_number = 3.0 hello = "Hello World!" true_ = True just_number = 6
Given: Print three times “Hello World!” within a while loop.
hello = "Hello World!" # declare "hello world" string
count = 2 # declare the count variable
true_ = True
# Print "Hello World!" phrase three times
while(true_):
print(hello)
count -= 1 # minus one
if(count < 0):
true_ = False
What the above Python program does is to set a count variable within the while loop that will control the number of times to print the “Hello World!” phrase on the screen!
from Planet Python
via read more
No comments:
Post a Comment