Saturday, 19 May 2018

Chaudhari Karan

Python Variable types

    5 comments:


Python Variable types

Hello friend, In this lecture, we will discuss python variable types.

Python variable types


Variable are reversed memory location. It is stored in value which means when creating the variable it is stored in some memory.

Data type variable, interpreter allocates memory and stored some memory in reversed memory. Variables assigning different types of data like integer, character, decimals, etc.

Assigning Values to a variable:


Python variable doesn't need an explicit declaration for the reversed memory location. For assign the value (=) sign is used. Variable automatic declares when assigning the value.

Operator left side is the name of the variable and its right side is value.

Example:
Python variable types


Output:
Python variable types


Multiple Assignment:

You can assign the single value to more than one variable.

Example:
Python variable types


Output:
Python variable types


Python provides more than variable to assign the same memory location.

Example:
Python variable types


Output:
Python variable types


Standard data types:

In standard data types data stored in the memory of many types. For example, person number, name, age, etc.

There are five types of Standard data types.
  • String
  • Numbers
  • List
  • Dictionary
  • Tuple

Python String:

Python string identifies as a set of character which is stored in quotes (‘ ‘)(" ").  For subset string using slice operator [] and [:]. Index staring with 0 beginning of the String.

Example:

Python variable types


Output:
Python variable types

Python Numbers:

Number data type is used for assign the numeric value. It is created when assigning the number.
For delete, the value del statement is used.

Example:
Python variable types



Python has four types of numerical:
  • Integer type(int)
  • Long type (long)   it can be represented in decimal, octal, and hexadecimal.
  •  Float type (float)
  • Complex type (complex)


Example:
int
Long
float
complex
10
0122L
0.0
3.14j
100
-0x19323L
13.36
.876j
-565
-0x19323L
-26.3
45.j
090
0xDEFABCECBDAECBFBAEl
35.6+e20
9.322e-36j
-096
-052318172735L
-69
3e+26J
-0x260
535633629843L
70.2-E18
-.6549+0J
0x69
-4721885298529L
-32.56e100
4.53e-7j

Python provide lowercase l for long but python recommended Uppercase L for avoiding the confusion with number 1.

A complex number consists of real floating point number. It is denoted by x+yj, where x,y is the real number and j is an imaginary unit.

Python Dictionary:

Python's dictionaries are hash table type dictionary. It is work like hashes found or associative arrays in Perl language and it is consist of key-value pairs.

A dictionary key is any Python type but is usually numbers or strings.

Example:
Python variable types


Output:
Python variable types


Python Tuples:


The tuple is another sequence data types it is similar to the list. It is consist of the number of values. It is separated by commas.

Difference between list and Tuple are: the list is enclosed by brackets [] and tuple are enclosed by parentheses ( ).

Example:
Python variable types


Output:
Python variable types


Here is invalid syntax with the tuple:

Python variable types

Data Type Conversion:


Data type conversion is used for convert one data type to another data type.

Here is some data type conversion

No.
                                            Function and Description
1
intx[,base]x[,base]
It converts x to the integer. if x is a string base is specific.
2
Floatxx
It converts x to a floating-point number.
3
longx[,base]x[,base]
It converts x to a long integer. base specifies the base if x is a string.
4
Strxx
Object x converts to the string representation.
5
complexreal[,imag]real[,imag]
It is creates a complex number.
6
Evalstrstr
It is evaluates a string and returns an object.
7
Reprxx
It is converts object x to an expression string.
8
Lists
It is converts s to a list.
9
Topless
It is converts s to a tuple.
10
Dictdd
It is creates a dictionary. d is a sequence of key,value of tuples.
11
Sets
It converts s to a set.
12
Chrxx
It is converts an integer to a character.
13
Frozensetss
It converts s to a frozen set.
14
Ordxx
It converts a single character to its integer value.
15
Unichrxx
It is converts an integer to a Unicode character.
16
Hexxx
It is converts an integer to a hexadecimal string.
17
Octxx
It converts an integer to an octal string.

Next: In next lecture, we will discuss python basic operator.

Subscribe to this Blog via Email :

5 comments

Write comments
Dipanwita
AUTHOR
13 August 2018 at 02:40 delete

This is a great blog post. very interesting. python training in Chennai

Reply
avatar
sathyaramesh
AUTHOR
31 December 2018 at 04:01 delete

I like your article very much. It has many useful ideas and suggestions. I thinks it will be more helpful for my research in an efficient manner. Please try to post some more topics as well as possible.
Python Training Institute in Chennai
Best Python Training in Chennai
best german classes in chennai
German language training in chennai
Devops Training in Chennai
RPA Training in Chennai

Reply
avatar
kim john
AUTHOR
7 February 2019 at 04:10 delete

In the beginning, I would like to thank you much about this great post. Its very useful and helpful for anyone looking for tips. I like your writing style and I hope you will keep doing this good working.
Data Science Course in Chennai
Data Science Training in Chennai
Blue Prism Training Chennai
AWS Training in Chennai
Digital Marketing Course in Chennai
Data Science Training in Porur
Data Science Training in Adyar
Data Science Training in Velachery

Reply
avatar