Data Type என்பது ஒரு variable எந்த வகையான value-ஐ store செய்கிறது என்பதை Python-க்கு தெரிவிக்கும் classification.
ஒரு data என்ன type என்பதை காட்டுவது Data Type.
Data Type என்பது ஒரு variable எந்த வகையான value-ஐ store செய்கிறது என்பதை Python-க்கு தெரிவிக்கும் classification. Simple definition: ஒரு data என்ன type என்பதை காட்டுவது Data Type.
Data Type என்பது ஒரு variable எந்த வகையான value-ஐ store செய்கிறது என்பதை Python-க்கு தெரிவிக்கும் classification.
ஒரு data என்ன type என்பதை காட்டுவது Data Type.
1x = 10
இங்கு 10 ஒரு integer value.
x → int data type.
name = "Python"
இங்கு "Python" text.
name → str data type.
int
float
bool
str
list
ஒரு வீட்டில் different containers இருப்பது போல நினைத்துக் கொள்ளுங்கள்.
Rice வைக்க ஒரு container.
Water வைக்க ஒரு bottle.
Books வைக்க ஒரு shelf.
அதே மாதிரி programming-ல் different kinds of values இருக்கும்.
1age = 25
25 → whole number.
int
1price = 99.50
99.50 → decimal number.
float
1passed = True
True → logical value.
bool
name = "Arun"
"Arun" → text.
str
marks = [80, 90, 75]
Multiple values collection.
list
Simple Memory
int → முழு எண்
float → decimal number
bool → True / False
str → Text
list → Multiple values
1x = 100
Five Data Types Flow
1Integer 2variable = integer_value
1age = 25 2Float 3variable = decimal_value
1price = 45.75 2Boolean 3variable = True
or
1variable = False
1is_active = True 2String 3variable = "text"
name = "Python"
name = 'Python'
List
variable = [value1, value2, value3]
marks = [80, 90, 75]
1Integer 2age = 25
1print(age) 2print(type(age))
25 <class 'int'>
25 <class 'int'>
| Step | Statement | Value | Data Type | Output |
|---|---|---|---|---|
| 01Iteration 1 | age = 25 | 25 | int | - |
| 02Iteration 2 | print(age) | 25 | int | 25 |
| 03Iteration 3 | type(age) | 25 | int | <class 'int'> |
int என்பது decimal point இல்லாத whole numbers-க்கு பயன்படுத்தப்படுகிறது.
10
-10
0
500
-999
int
10.0 ஒரு integer.
இல்லை.
x = 10.0
float
because decimal point இருக்கிறது.
INT = Integer = முழு எண்
Decimal point இல்லை → int
Python integer data type is represented by int.
10
0
-25
500
What is an integer in Python?
Answer
An integer is a whole number without a decimal point. Python represents integer values using the int data type.
10 20 0 -50 1000
1x = 100
x = -100
1x = 0
All are int.
All are int.
1Integer Arithmetic 2a = 10 3b = 5
1print(a + b) 2print(a - b) 3print(a * b)
15 5 50 Integer Check x = 50
15 5 50 Integer Check x = 50
1print(type(x))
<class 'int'>
<class 'int'>
Float என்பது decimal point கொண்ட numeric values store செய்ய பயன்படும் Python data type.
10.5 3.14 99.99 -7.5 0.0
10
→ int
10.5
→ float
Point இருந்தால் பொதுவாக float என்று நினைவில் வைத்துக்கொள்ளலாம்.
1price = 99.50
1variable = decimal_value
1height = 5.8
1price = 99.50
1print(price) 2print(type(price))
99.5 <class 'float'>
99.5 <class 'float'>
| Step | Statement | Value | Type | Output |
|---|---|---|---|---|
| 01Iteration 1 | price = 99.50 | 99.5 | float | - |
| 02Iteration 2 | print(price) | 99.5 | float | 99.5 |
| 03Iteration 3 | type(price) | 99.5 | float | <class 'float'> |
10
→ int
10.0
→ float
Value mathematically same போல இருந்தாலும் Python data type different.
x = 5.
float
because decimal notation பயன்படுத்தப்பட்டுள்ளது.
print(type(5.0))
<class 'float'>
FLOAT = Floating decimal point
Decimal point → float
Python floating-point numbers are represented using the float data type.
What is the difference between int and float?
Answer
int stores whole numbers without a decimal point. float stores floating-point or decimal numbers.
Boolean என்பது True அல்லது False என்ற இரண்டு logical values-ஐ represent செய்யும் data type.
bool
Boolean-ஐ ஒரு Yes / No switch போல நினைக்கலாம்.
Yes → True
No → False
1is_student = True
True
Student ஆ? → Yes.
Absent ஆ? → No.
10 > 5
10 greater than 5.
Yes.
True
1variable = True
or
1variable = False
True
False
true
false
Python case-sensitive.
1passed = True
1print(passed) 2print(type(passed))
True <class 'bool'>
True <class 'bool'>
| Step | Expression | Meaning | Result |
|---|---|---|---|
| 01Iteration 1 | 10 > 5 | Is 10 greater than 5? | True |
| 02Iteration 2 | 10 < 5 | Is 10 less than 5? | False |
| 03Iteration 3 | 10 == 10 | Are both equal? | True |
True
False
Capital T and capital F முக்கியம்.
x = True
x = true
NameError
because Python true என்பதை variable name போல எடுத்துக்கொள்ளும்.
BOOL = Boolean = Two values
True / False
The Boolean data type in Python has two values: True and False.
What is Boolean data type in Python?
Answer
The Boolean data type represents logical values. Python uses True and False, and its type name is bool.
String என்பது characters அல்லது text-ஐ represent செய்யும் sequence data type.
str
name = "Python"
Letters, words, sentences, numbers-as-text போன்றவற்றை quotes உள்ளே எழுதினால் அது string.
"Hello"
→ String
"Python Programming"
→ String
"123"
→ இதுவும் String.
ஏன்?
123 quotes உள்ளே இருக்கிறது.
"369 Tesla"
variable = "text"
variable = 'text'
name = "Python"
or
name = 'Python'
இரண்டும் valid.
name = "Python"
1print(name) 2print(type(name))
Python <class 'str'>
Python <class 'str'>
| Character | P | y | t | h | o | n |
|---|---|---|---|---|---|---|
| Index | 0 | 1 | 2 | 3 | 4 | 5 |
print(word[0])
word = "Python"
P
Negative Index
word = "Python"
print(word[-1])
n
-1 → last character.
String Concatenation
first = "Hello"
second = "Python"
print(first + " " + second)
Hello Python
- strings-ல் concatenation செய்யும்.
String Repetition
print("Hi " * 3)
Hi Hi Hi
Length of String
name = "Python"
print(len(name))
6
1name = "Python" 2print(name[0])
<class 'int'> <class 'str'>
| Step | Statement | Value | Output |
|---|---|---|---|
| 01Iteration 1 | name = "Python" | Python | - |
| 02Iteration 2 | name[0] | First character | P |
| 03Iteration 3 | print() | P | P |
123
→ int
"123"
→ str
print(type(123))
print(type("123"))
<class 'int'> <class 'str'>
name = Python
Python இதை text என்று எடுத்துக்கொள்ளாது.
Python என்ற variable இருக்கிறதா என்று பார்க்கும்.
NameError
name = "Python"
STR = String = Text
Quotes உள்ளே → String.
Strings in Python are sequences of characters enclosed within quotes and are represented by the str type.
What is a string in Python?
Answer
A string is a sequence of characters used to represent text. Python strings can be written using single or double quotation marks.
List என்பது multiple values-ஐ ஒரே variable-ல் ordered collection ஆக store செய்யும் Python data type.
[]
marks = [80, 90, 70]
ஒரு student-க்கு 5 marks இருக்கிறது என்று வைத்துக்கொள்வோம்.
m1 = 80 m2 = 90 m3 = 70 m4 = 85 m5 = 95
marks = [80, 90, 70, 85, 95]
ஒரே variable-ல் multiple values store செய்யலாம்.
இதுதான் list.
[10, 20, 30]
list_name = [item1, item2, item3]
numbers = [10, 20, 30]
languages = ["Python", "Java", "C"]
data = [10, 5.5, "Python", True]
Python list different data types-ஐ contain செய்ய முடியும்.
numbers = [10, 20, 30]
1print(numbers) 2print(type(numbers))
[10, 20, 30] <class 'list'>
[10, 20, 30] <class 'list'>
| Value | 10 | 20 | 30 |
|---|---|---|---|
| Index | 0 | 1 | 2 |
List is mutable.
print(numbers[0])
10
Second Element
print(numbers[1])
20
Last Element
print(numbers[-1])
30
Change a List Value
Mutable என்றால் value-ஐ change செய்யலாம்.
numbers = [10, 20, 30]
numbers[1] = 200
print(numbers)
[10, 200, 30]
Add Element - append()
numbers = [10, 20, 30]
numbers.append(40)
print(numbers)
[10, 20, 30, 40]
Remove Element
numbers = [10, 20, 30]
numbers.remove(20)
print(numbers)
[10, 30]
List Length
numbers = [10, 20, 30, 40]
print(len(numbers))
4
1numbers = [10, 20, 30] 2numbers.append(40) 3print(numbers)
| Step | Statement | List Value | Output |
|---|---|---|---|
| 01Iteration 1 | Create list | [10,20,30] | - |
| 02Iteration 2 | append(40) | [10,20,30,40] | - |
| 03Iteration 3 | print(numbers) | [10,20,30,40] | [10,20,30,40] |
Ordered
Indexed
Mutable
Allows duplicate values
Can contain different data types
data = [10, 10, "Python", 5.5, True]
Valid list.
[]
x = [10, 20, 30]
(10, 20, 30)
This is a tuple, not a list.
LIST = List of many values
[] → List.
A Python list is an ordered and mutable collection represented using square brackets.
What is a list in Python?
Answer
A list is an ordered, mutable collection of values. It is represented using square brackets and can contain duplicate as well as mixed data types.
| Data Type | Meaning | Example | Symbol / Form |
|---|---|---|---|
| int | Whole number | 10 | Number |
| float | Decimal number | 10.5 | Decimal |
| bool | Logical value | True | True/False |
| str | Text | "Python" | Quotes |
| list | Multiple values | [10,20] | [ ] |
| Point | int | float | bool | str | list |
|---|---|---|---|---|---|
| Example | 10 | 10.5 | True | "Hi" | [10,20] |
| Numeric? | Yes | Yes | Logical | No | Collection |
| Quotes needed? | No | No | No | Yes | Depends on items |
| Multiple values? | No | No | No | Characters | Yes |
| Indexed? | No | No | No | Yes | Yes |
| Mutable? | Not in-place | Not in-place | Not in-place | No | Yes |
Python Automatically Determines Data Type
Python-ல் usually variable declaration-ல் type எழுத வேண்டியதில்லை.
int x = 10;
x = 10
Python automatically
int
என்று determine செய்கிறது.
இதனை dynamic typing உடன் தொடர்புபடுத்தலாம்.
type() Function
type(value)
1x = 10 2print(type(x))
<class 'int'> All Types Example a = 10 b = 10.5 c = True d = "Python" e = [10, 20, 30]
<class 'int'> All Types Example a = 10 b = 10.5 c = True d = "Python" e = [10, 20, 30]
1print(type(a)) 2print(type(b)) 3print(type(c)) 4print(type(d)) 5print(type(e))
<class 'int'> <class 'float'> <class 'bool'> <class 'str'> <class 'list'>
<class 'int'> <class 'float'> <class 'bool'> <class 'str'> <class 'list'>
a = 10
10 whole number.
Type → int.
b = 10.5
Decimal value.
Type → float.
c = True
Logical value.
Type → bool.
d = "Python"
Text inside quotes.
Type → str.
e = [10, 20, 30]
Multiple values inside square brackets.
Type → list.
| Trace | Variable | Value | Python identifies as |
|---|---|---|---|
| 01 | a | 10 | int |
| 02 | b | 10.5 | float |
| 03 | c | True | bool |
| 04 | d | "Python" | str |
| 05 | e | [10,20,30] | list |
10 and "10" same என்று நினைப்பது
10 → int
"10" → str
Completely different types.
True quotes உள்ளே எழுதுவது
x = True → bool
But:
x = "True" → str
List brackets confuse செய்வது
[1, 2, 3] → list
"1, 2, 3" → string
bool value lowercase
x = false
x = False
Float-ஐ int என்று நினைப்பது
x = 10.0
Type:
float
int represents whole numbers.
float represents floating-point numbers.
True
False
Python Boolean type is:
bool
String type is:
str
Strings are enclosed in quotes.
[ ]
square brackets.
List is mutable.
String is immutable.
Python type() function identifies the type of an object.
10
is int.
10.0
is float.
"10"
is str.
[10]
is list.
Python is dynamically typed; explicit variable type declaration is generally not required.
What is a data type?
Answer
A data type identifies what kind of value an object represents and what operations are appropriate for it. Examples include integer, float, Boolean, string and list.
How do you find a variable's type in Python?
Answer
The built-in type() function is used.
1x = 10 2print(type(x))
What is the difference between 10 and "10"?
Answer
10 is an integer, while "10" is a string because it is enclosed in quotation marks.
What is the difference between a string and a list?
Answer
A string is an immutable sequence of characters. A list is a mutable ordered collection that can contain multiple values and different data types.
Can a Python list contain different data types?
Answer
Yes.
data = [10, "Python", 5.5, True]
Identify the data types:
a = 100 b = 9.5 c = False d = "Computer" e = [1, 2, 3]
Answer:
Use type() and check:
x = 500
Create a float variable called salary.
1salary = 25000.50
200
Create a Boolean variable:
is_passed = True
Create a string containing your name.
name = "Your Name"
Create a list containing 5 marks.
marks = [80, 90, 75, 85, 95]
Print the second element:
numbers = [100, 200, 300]
Answer:
print(numbers[1])
200
Find the output:
x = "10" y = "20" print(x + y)
1020
Reason:
Both are strings.
Find the output:
x = 10 y = 20 print(x + y)
30
Reason:
Both are integers.
Find the difference:
x = True y = "True"
Answer: