Description

Variable is used for store the data in python programming language. The value of variable can be changed, and variable reused many times.

Syntax of Create Variable in Python Programming

Python has no command for declaring a variable.

var1 = 5;
name = "JOHN"
print(var1)
print(name)

Output:

5
JOHN

In Python Programming language, variables do not need to be declared with any particular type.

Type casting in Python Programming

The type casting is one data types to another data types.

x = str(5)    # x will be '5' as a string
y = int(5)    # y will be 5 as a integer
z = float(5)  # z will be 5.0 as a float

How to get the type of variable

You can get the data type of any variable using the type() function.

x = 8
y = "lapmos"
print(type(x))
print(type(y))

Output:

<class 'int'>
<class 'str'>

 

Single or Double Quotes in string

String is declared either by using single quotes or double quotes.

x = "JAMES"   # x is a string and valid
x = 'JAMES'   # valid
# both are same

Case Sensitive in Python programming

In Python programming language, Variables names are case-sensitive.

x = 5
X = "JAMES"
# x and X are the different variable 

Rules of Declaration Variable in Python Programming

  • A variable starts with the alphabets or underscore in python.
  • A variable can not start with number and any digits in python.
  • No white space allowed to declare the variable in python programming.
  • No Special Characters Allowed except underscore.
  • Variable are case-sensitive.
#Valid / Legal variable names
var = "lapmos"
var1 = "lapmos"
var_ = "lapmos"
_var = "lapmos"
VAR = "lapmos"

Multiple Variables in one line.

Python allows you to assign values to multiple variables in one line:

a, b, c = "JOHN", "JAMES", "NICK"
print(a)
print(b)
print(c)

Output:

JOHN
JAMES
NICK

One Value to Multiple Variable at the one line.

a = b = c = "JOHN"
print(a)
print(b)
print(c)

Output:

 

JOHN
JOHN
JOHN

Datatypes in Python Programming

The Data types specifies the type of data that the variable can store the value.

Python has six basic data types which are as follows:

  1. Numeric 
  2. String
  3. List
  4. Tuple
  5. Dictionary
  6. Boolean

Keywords Python Programming language

Keywords is reserved word in Python Programming language. Keywords can not use as a variable. Keyword in Python Programming language :

and del from None
True as elif global
nonlocal try assert else
if not while break
except import or with
class false in pass
yeild continue finally is
raise def for lambda
return      

 

Comments

Login is mandatory to comment Please login

Recommended Posts

Operators | Types of Operators in Python Programming

Operator is a symbol that tells the computer to perform the mathematical and logical operation in python programming. Operators are used in program to manipulate the data and variable.

All About of String in Python Programming language

In Python It is called a string which is inside single or double quotation marks. We can write multiline string inside three single or double quotation mark.

List and Tuple in Python Programming

List is a kind of data structure in Python which is mutable, changeable, ordered sequence. Tuples are used to store multiple items in a single variable.

Dictionary In Python | Method Of Dictionary

Dictionary is used to store data values in Key: Value pairs. A dictionary is a collection which is ordered, Changeable and do not allow duplicates.

Implement of All Method of String in Python Programming language

Implementation of all methods of string in python. How to implement of method on string.

Operators based Exercise 1 in Python Programming language.

All operators used for better understanding the python operators.