# Variable Creation pi = 3.14 number = 5 Name = "John"
foo = 5 # foo is an integer type variable foo = "John" # now, foo is a string type variable # you can assign different data types # to the same variable, because # Python is a dynamically-typed language.
Concatenating with + Operator
You can use + operator to concatenate two string variables. However you cannot concatenate a string and an integer value, it will raise a
TypeError. Since Python does not convert an integer to string implicitly, you need to use the built-in
str() function to convert an integer to string value.
hello = "Hello " number = 5 print(hello + number)
hello = "Hello " number = 5 print(hello + str(number))
- A variable name should start with a letter or an underscore (_) character.
- A variable name can contain any alphabetic (A-Z a-z), numeric (0-9) or underscore (_) character but the first character cannot be numeric.
- Variable names are case sensitive (MyVar, myvar, myVar all refer to different variable).