Python is completely object oriented, and not “statically typed”. You do not need to declare variables before using them, or declare their type. Every variable in Python is an object.
Numbers
To define an integer, use the following syntax:
my_int = 11
To define a floating point number, you may use one of the following notations:
my_float = 11.0 # You can also use the below syntax my_float = float(11)
Strings
Strings are defined either with a single quote or a double quotes.
my_string = 'InterviewBit' my_string = "InterviewBit"
The difference between the two is that using double quotes makes it easy to include apostrophes (whereas these would terminate the string if using single quotes)
my_string = "Don't worry about it"
Operators between numbers and strings is not supported:
my_int = 11 my_string = "InterviewBit" my_intstring = my_int + my_string
NOTE: Above code will not work.
Try the following example in the editor below.
You have to assign the following values in the variable: