position: fixed; top: auto !important; margin-left: 112px;

Python Variables

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} \nage is {1}".format(x,age))

Previous Next Article







codzify.com


Largest collection of up-to-date tutorials to learn programming languages. We are focused on easy learning. Massive collection of interview questions one may need for preparation.

Social Profile


Linkedin
Twitter
Facebook

Copyright 2018. All rights reserved.