2. Different Data types:
Computer programming is all about processing data. In computer programming, the
data is always represented in the binary form (0's and 1's), i.e. groups of Bits called as
Bytes.
In the real world, we come across different types of data like age of a
person(integer), number of rooms in a house (integer), price(floating-point number),
height (floating-point number), Names of people, places and things (strings),
inventory list (list) etc.
In Python data types are used to classify data to one particular type of data.
3. The data type of the data determines : possible values it can be assigned.
• Possible operations that can be performed. (Arithmetic operations can be
applied on numeric data and not strings)
• The format in which it is stored in the memory.
• The amount of memory allocated to store the data.
1.Some of the built-in data types supported in Python are:
Number
2.String
3.List
4.Tuple
5.Set
6.Dictionary
4. In Python, every value has a data type.
A variable in Python can hold value of any data type.
The same variable in Python can refer to data of different data types at different times.
So variables in Python are not (data) typed.
5.
6. Select the correct statements
A. In Python, we need not specify the data type of the variable.
B. The return type of type() function is string.
C. In Python we have 'varchar' data type.
D. type() function in Python is used to know which datatype of
value the variable holds.
7. Numbers
We have three different categories of numbers in Python. They are :
1.int
2.float
3.complex
1.int – int stands for integer. This Python data type stores signed
integers. We can use the type() function to find which class it
belongs to.
2.float – float stands for floating-point numbers. This Python data
type stores floating-point real values. An int can only store the
number 20, but float can store numbers with decimal fractions
like 20.25 if you want.
3.complex – complex stands for complex numbers.
This Python data type stores a complex number. A complex number
is a combination of a real number and an imaginary number. It takes
the form of a + bj Here, a is the real part and b*j is the imaginary
8. Strings
In Python, string is a sequence of characters enclosed inside a pair of
single quotes(‘) or double quotes(“). Even triple quotes (''') are used
in Python to represent multi-line strings.
The computer doesn’t see letters at all. Every letter you use is
represented by a number in memory.
For example, the letter A is actually the number 65. This is
called encoding. There are two types of encoding for characters –
ASCII and Unicode.
ASCII uses 8 bits for encoding whereas Unicode uses 32
bits. Python uses Unicode for character representation.
9. An individual character within a string is accessed using an index.
Index starts from 0 to n-1, where n is the number of characters in
the string.
Python allows negative indexing in strings. The index of -1 refers to
the last item in the string, -2 refers to the second last item and so
on.
10. Ways of creating strings in Python :
1. Using single quotes (' ‘)
str = 'Welcome To Python World'
print(str)# will print the string
2. Using double quotes (" ")
sentence = "Welcome to Python's world"
print (sentence) # will print
3. Using triple double quotes(""" """)
We use triple double quotes(""" """) to create
multi-line strings in Python.
11. Select all the correct statements given
below.
A. a = 'A' is a valid character in Python.
B. str = 'Welcome to python's world' is a valid string creation.
C. Encoding means converting strings of characters into
numbers.
D. Triple quotes are used for only multi-line strings.