20220520 105417
Built-in Data Types
In programming, data type is an important concept.
Variables can store data of different types, and different types can do different things.
Python has the following data types built-in by default, in these categories:
Text Type: str
Numeric Types: int, float, complex
Sequence Types: list, tuple, range
Mapping Type: dict
Set Types: set, frozenset
Boolean Type: bool
Binary Types: bytes, bytearray, memoryview
None Type: NoneType
-----------------------------
data types: int, string, float, complex
List tuple set dictionary
Variables
Variables are containers for storing data values.
a=10
print(a)
type(a)
class'int'
b = 'Hello'
b
'Hello'
print(b)
Hello
type(b)
class 'str'
c = 11.23
print(c)
11.23
type(c)
class 'float'
a = b = c = 124
a
124
b
124
c
124
x, y, z = 12, 15, 18
x
12
y
15
z
18
a = [1,4,7,9,12]
a
[1, 4, 7, 9, 12]
--------------
a1 = 10
a1
10
1a=11
SyntaxError: invalid decimal literal
a b =12
SyntaxError: invalid syntax
a-x=12
SyntaxError: cannot assign to expression here. Maybe you meant '==' instead of '='?
----------------------------------------
_a = 13
_a
13
a_ = 12
a_
12
_a_b =14
_a_b
14
My_Name='Latif'
myName="Tanu"
myName
'Tanu'
MyName="Devashri"
MyName
'Devashri'
_My_Name= "Rituja"
name1='Pragathi"
SyntaxError: unterminated string literal (detected at line 1)
name2 = 'Pragathi "Amravati" Pune'
name2
'Pragathi "Amravati" Pune'
name3 = "Savantis 'Pune' CTS"
name3
"Savantis 'Pune' CTS"
name4 = 'Savatis 'CTS' Pune'
SyntaxError: invalid syntax
name5 = 'Savatis
SyntaxError: unterminated string literal (detected at line 1)
---------------
a =100
b =120
a+b
220
type(a)
class 'int'
type(b)
class 'int'
c='102'
type(c)
class 'str'
a+c
Traceback (most recent call last):
a+c
TypeError: unsupported operand type(s) for +: 'int' and 'str'
myName
'Tanu'
myName+c
'Tanu102'
--------------------
a = str(22)
a
'22'
b = int(24)
b
24
type(a)
class 'str'
type(b)
class 'int'
c = float(28)
c
28.0
type(c)
class 'float'
------------------
x
12
y
15
str(x) + str(y)
'1215'
x+y
27
myName
'Tanu'
myName+str(x)
'Tanu12'
type(x)
class 'int'
--------------------------------------------------
Multi Words Variable Names
Variable names with more than one word can be difficult to read.
There are several techniques you can use to make them more readable:
Camel Case
Each word, except the first, starts with a capital letter:
myVariableName = "John"
Pascal Case
Each word starts with a capital letter:
MyVariableName = "John"
Snake Case
Each word is separated by an underscore character:
my_variable_name = "John"
----------------------------------------
a =100
type(a)
class 'int'
print(a)
100
s = 'Sameer'
SyntaxError: unexpected indent
s='Sameer'
type(s)
class 'str'
print(s)
Sameer
print(s+a)
Traceback (most recent call last):
print(s+a)
TypeError: can only concatenate str (not "int") to str
print(s,a)
Sameer 100
-------------------------------------------
print("s")
s
print(s)
Sameer
print("My name is",s)
My name is Sameer
print(f"My name is {s}, my no is {a}")
My name is Sameer, my no is 100
p1= '''this is para for python
string , practice variables
python is data type'''
p1
'this is para for python\nstring , practice variables\npython is data type'
print(p1)
this is para for python
string , practice variables
python is data type
p2 = """ three double cots to write
paragraph , learn python
by practice, docs in python.org
helps to learn"""
print(p2)
three double cots to write
paragraph , learn python
by practice, docs in python.org
helps to learn
-------------------------
print("Hello, I am rutuja, \nNagpur")
Hello, I am rutuja,
Nagpur
-------------------------
Watch video (B17) Python part3 Varialbles - Data Types - Int, str, float, Strings , print statements online without registration, duration hours minute second in high quality. This video was added by user Latif Shaik (latiftechnotes) 20 May 2022, don't forget to share it with your friends and acquaintances, it has been viewed on our site 29 once and liked it 0 people.