Test your Programming knowledge

50% users failed to get the best score. It's your turn to test now.
Questions curated by the expert mentors at codzify.com

Start Quiz


Python Variables - Codzify.com

1 min 29 sec read

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,

Example 1

x = 5 print(x)

Example 2

x = "Hello world" print(x)

Example 3

x = "Hello world" print("String is " + x)

Example 4

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))

Recommended Articles

Did you found this article helpful?

Try to execute what you have learnt

Easy to use online data structure compiler where you can execute the programs in your favourite programming language.
(C, C++, Python)

Open Compiler

HTML, CSS and Javascript Real time Web Editor

Execute your HTML, CSS and javascript code in real time with the web editor
(HTML, CSS, Bootstrap, Javascript)

Open Web Editor