Data Types and Models in Python | Python course for beginners.Python Courses | Session_4
Data Types and Models in Python
Data Types and Models impotent All Programming Languages Not Only in Python you should understand Esaly don't worry let's begin.
Following Topics, We discussing In python
- Numbers
- String
- List
- Tuple
- Set
- Dictionary
1.Numbers
Integers and real numbers and complex numbers come under the numbers category. They are mention int, float, and complex class in python.
>>a=27
>>type(a)
<class 'int'>
>>a=5.5
>>type(a)
<class 'float'>
Example
>>a=27
>>type(a)
<class 'int'>
>>a=5.5
>>type(a)
<class 'float'>
>>a=27+20j
<Class 'Complex'>
Also, Python has some spacial Automatically find data Types whatever you put in the Script.
This is amazing right!
2.String
The string is a Sequence of UNICODE characters. the user can use single quotes or double quotes to represent the strings. strings are immutable object in python
Example
>> blog = "Hello techtrainer.site"
>>print("blog[4]=".blog[4])) #Hello
>>print("s[6,11]"=".s[6,11]) #Tech
3.List
The List is Stored as an ordered sequence of items, these items are mutable items separated by commas are enclosed within square brackets"[]" or list
Example
>> a = [6,3,80,36,40,43]
>>print("a[2] =".a[2]) # Output 80
>>print("a[0.3] =".a[0.3]) #output 6,3,80,36
>>print("a[5] = ".a[5]) #ouput 43
4.Tuple
A tuple is an ordered sequence of items, the same as the list. The main difference is that tuples are immutable it is defined with parentheses () or tuple() where items are separated by commas.
Example
>>t=(5,"TechTrainer",1+6j)
>>print("t[1] =".t[1]) #output 5
>>print("t[0.3]=".t[0.3]) #ouput 5,"TechTrainer,1+6j
5.set
The Set is an unordered collection of unique elements immutable behavior A set defined by values separated by commas inside curly braces {}.Example
>>a={10,2,30,400,5}
>>print("a =",a) #output: 10,2,30,400,5
>>print(type(a)) #output <class set>
6.Dictionary
The Dictionary is an unordered collection of key-value pairs. The Declaration of the dictionary without any items is written with just two curly braces{}
Example
>>dict = {'Name':'Prathish','Age':10}
>>print(type(dict))
<class dict>
>>print("dict[1]=".dict[1]); #Output Name prathish
Variables
Python does not have to declare any type of the variable This is handled internally
according to the type of value assigned to the variable.
Example
>>>Name = "Parthish"
>>>age = 10
0 comments: