prev
next
Or press ESC to close.
To continue enjoying our content, please consider disabling your ad blocker. Your support helps us continue providing quality content. To continue enjoying our content, please consider disabling your ad blocker. Your support helps us continue providing quality content.

Python Programming Part 03

Rajjit Sept 16th, 2023 15 mins read
part-03

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:

  • Text type - str
  • Numeric type - int, float, complex
  • Sequence type - list, tuple, range
  • Mapping type - dict
  • Set types - set, frozenset
  • Boolean type - bool
  • Binary type - bytes, bytearray, memoryview
  • None type - NoneType
Setting the data type:
For text type - str
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))
Video tutorial:
Setting the specific data type

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 ''' '''.

  • Single line comment (#): It can be used to comment out a single line of code or write a note about that section of the code
  • Multiple line comment (''' '''): It can be used to comment out multiple lines of code, a condition of a code, a whole section of a code and even write documentation of the code.
Comments serve as a form of self-documentation, making it easier to understand, debug, and maintain your code. They can save time and effort when you or others revisit the code months or years later, helping to prevent confusion and errors.

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