TOPIC: Python Data Types & Comments
Built-in Data Types:
In programming, data type is an important concept. There
are some
Built-in data types in python and are given as follows:
x = "Hello World"
For numeric type - int
x = 5
For numeric type - float
x = 3.5
For numeric type - complex
x = 5j
For sequence type - list
x = ["red", "blue", "green"]
For sequence type - tuple
x = ("red", "blue", "green")
For sequence type - range
x = range(10)
For mapping type - dict
x = {"name":"rj", "blog":"rjs blog"}
For set type - set
x = {"rj", "rjs blog"}
For set type - frozenset
x = frozenset({"rj", "rjs blog"})
For boolean type - bool
x = True
y = False
For bytes type - bytes
x = b"Hello"
For bytes type - bytearray
x = bytearray(3)
For bytes type - memoryview
x = memoryview(bytes(3))
For none type - None
x = None
In order to run the code and print the output with the type of data-type, we use
print(x)
print(type(x))
We can also set the specific data type to a variable if we want to make it fixed. We can do that by
x = int(2)
We can remove the int from the above code and add any other data-type to make it fixed for that variable.
Comments in Python Programming
There are two types of comments in Python programming, the single line comment that uses # and the
multiple line comment that uses ''' '''.
Code as discussed in the video:
# Python Data Types and Comments
''' Built in Data Types
1. Text Type - string (str)
2. Numeric Type - int, float, complex
3. Sequence Type - list, tuple, range
4. Mapping Types - dict
5. Set type - set, frozenset
6. Boolean - bool
7. Binary - byte, bytearray, memoryview
8. None type - None Type
'''
# str
x = "Hello World!"
# print(x)
#int
y = 15
# print(y)
# float
z = 2.5
# print(z)
# complex
a = 7j
# print(a)
# list
list = ["red", "blue", "green"]
# print(list)
# tuple
tup = ("red", "blue", "green")
# print(tup)
# range
rang = range(1, 10)
# print(rang)
# dict
dict = {"name":"rajjit", "channel":"rj coding tips"}
# print(dict)
# set
set = {"red", "green", "blue"}
# print(set)
# frozenset
frozens = frozenset({"red", "green", "blue"})
# print(frozens)
# bool
b = True
# print(b)
c = False
# print(c)
# byte
d = b"Hello"
# print(d)
# bytearray
e = bytearray(5)
# print(e)
# memoryview
f = memoryview(b"Hello")
# print(f)
# nonetype
name = None
# print(name)
# print(type(b))
# There are two types of comment in python
# single line comment
# user21354
'''
Multiple line comment
'''
'''def sample():
new = 5
print(new)
sample()'''
You can copy and run this code