Online Classes

Results can only be achieved if you have the focused direction and crystal clear knowledge. To achieve this, you need a mentor. We will help you out by connecting with an expert mentor in the field.

Learn More


Python Variables -

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

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