A variable is a name that refers to a value.
>> message = 'Hello'
>>> n = 18
>>> pi = 3.1415
A first assigns a string to a new variable named message the second assigns the integer 17 to n
the third assigns the value of pi.
you can use the print statement to display value.
>>> print(n)
18
>>> print(message)
Hello
Total 3 variables called string, integer and float.
Note: I showed some example of illegal character.please check it out below.
you cannot define the number in value
>>> 1 = a
SyntaxError: can't assign to literal
class is one of python keyword you cannot use
>>> 1 = a
SyntaxError: can't assign to literal
more@ is an illegal character you cannot use
>>> 1 = a
SyntaxError: can't assign to literal
Additional example
1.swap variable value
>>>a, b = 1, 2 >>>a, b = b, a
>>>print('a')
2
>>>print('b)
1
2.Concatenation -> combine strings and integer
>>> print ‘red’ + str(3)
red3
>> message = 'Hello'
>>> n = 18
>>> pi = 3.1415
A first assigns a string to a new variable named message the second assigns the integer 17 to n
the third assigns the value of pi.
you can use the print statement to display value.
>>> print(n)
18
>>> print(message)
Hello
Total 3 variables called string, integer and float.
Note: I showed some example of illegal character.please check it out below.
you cannot define the number in value
>>> 1 = a
SyntaxError: can't assign to literal
class is one of python keyword you cannot use
>>> 1 = a
SyntaxError: can't assign to literal
more@ is an illegal character you cannot use
>>> 1 = a
SyntaxError: can't assign to literal
Additional example
1.swap variable value
>>>a, b = 1, 2 >>>a, b = b, a
>>>print('a')
2
>>>print('b)
1
2.Concatenation -> combine strings and integer
>>> print ‘red’ + str(3)
red3
No comments:
Post a Comment