Ravindra Bagale · Data Scienceसर्व coursesया course चे lessonsशोधाEnglish

Data Science · मराठी आवृत्ती · Python basics

P2.2 Python Data Types: int, float, str आणि bool

By Ravindra Bagale

हे का शिकायचं?

प्रत्येक value चा type ठरवतो की तिच्यावर कोणतं काम करता येईल. "500" (text) आणि 500 (number) वेगळे आहेत.

हे काय आहे?

int म्हणजे पूर्ण संख्या, float म्हणजे दशांश संख्या, str म्हणजे text आणि bool म्हणजे True किंवा False. type() ने कुठल्याही value चा type कळतो.

कसं करायचं?

Step 1. Value लिहा.

Step 2. type(value) चालवा.

Step 3. Output मधला type वाचा.

उदाहरणं: copy करा आणि चालवा

उदाहरण A: चार types तपासा

हा code चालवा:

age = 34
balance = 2500.75
name = "Emma"
is_active = True
print(type(age))
print(type(balance))
print(type(name))
print(type(is_active))

तुम्हाला दिसणारा output:

<class 'int'>
<class 'float'>
<class 'str'>
<class 'bool'>

याचा अर्थ: type() प्रत्येक value चा type दाखवतो: int, float, str, bool.

उदाहरण B: Number विरुद्ध number सारखा दिसणारा text

हा code चालवा:

a = 500
b = "500"
print(a + a)
print(b + b)

तुम्हाला दिसणारा output:

1000
500500

याचा अर्थ: Text ची बेरीज म्हणजे जोडणं, number ची बेरीज म्हणजे गणित. CSV मधले आकडे बऱ्याचदा text असतात.

उदाहरण C: True आणि False सुद्धा numbers आहेत

हा code चालवा:

paid = [True, False, True]
print(sum(paid))

तुम्हाला दिसणारा output:

2

याचा अर्थ: True = 1 आणि False = 0. म्हणून True values ची sum केली की count मिळतो.