Like in other programming languages, python variables are flexible enough. There is no need to write any type before variable names. A variable can have a short name (like a and b) or a more descriptive name (count, studentInfo). More descriptive variable names must be recommended for better understanding of code and flexibility.
Rules for Python variables:
1) A variable name must start with a letter or the underscore character.
2) A variable name cannot start with a number.
3) A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
4) Variable names are case-sensitive (student, Student, and STUDENT are three different variables) For example,
x = 5 print(x)
x = "Hello world" print(x)
x = "Hello world" print("String is " + x)
To print both int variables and string variables in python 3, you have to use str.format method where str includes the string and {0} and {1} are placeholders for arguments which will then replaced by their values inside format.
x = "Hello world" age = 3 print ("String is {0} age is {1}".format(x,age))
Unlock learning opportunities with our expert-led coding courses.
Real-time doubt solving in a live online coding class is also available in the course
that will help you to stay connected with an experts while learning.