← Back to Python Course | Chapter 1: Basics | Lesson 8 of 14

Python Data Types

Data types किसी प्रोग्राम में रखी जा सकने वाली अलग-अलग तरह की चीज़ें हैं, जैसे numbers, शब्द, और हाँ-या-ना वाले जवाब। यह खिलौनों को अलग-अलग बक्सों में छाँटने जैसा है, क्योंकि हर तरह का उपयोग अलग होता है।
Syntax
python
variable = value  # int, float, str, bool, list, tuple, dict, set
type(variable)

Numbers

Python में पूर्ण और भिन्नात्मक values के लिए दो built-in numeric types हैं: मनमाने आकार के integers के लिए int, और दशमलव बिंदु वाली संख्याओं के लिए float

Interpreter केवल इस बात से अनुमान लगाता है कि आपने कौन सा इरादा किया, कि value assign करते समय आपने दशमलव बिंदु लिखा या नहीं।

उदाहरण: Numbers

python
age = 25  # whole number, Python infers this as an int
price = 19.99  # has a decimal point, Python infers this as a float
print(type(age))  # shows <class 'int'>
print(type(price))  # shows <class 'float'>

Strings

str अक्षरों का क्रमबद्ध अनुक्रम है, जो single या double quotes से बनता है, और हर text-आधारित चीज़ के लिए इस्तेमाल होता है — नाम, संदेश, file paths, parse किया हुआ data।

Strings indexing, slicing और हेरफेर के लिए built-in methods का बड़ा समूह support करती हैं।

उदाहरण: Strings

python
name = "Python"
print(name[0])  # first character, indexing starts at 0
print(name[1:4])  # slice: characters from index 1 up to (not including) 4
print(name.upper())  # built-in method returns an uppercase copy

Booleans

bool के ठीक दो values हैं, True और False (ज़्यादातर भाषाओं के विपरीत, पहला अक्षर capital), और हर comparison और logical operator यही लौटाता है। भीतर से True और False क्रमशः 1 और 0 की तरह व्यवहार करते हैं, इसलिए वे arithmetic में भी भाग ले सकते हैं।

उदाहरण: Booleans

python
is_ready = True  # capitalized True/False are the only bool values
print(is_ready)
print(True + True)  # True behaves like 1, so this adds up to 2

Lists

list एक क्रमबद्ध संग्रह है जिसे आप बनाने के बाद बढ़ा, घटा और बदल सकते हैं, और जो [1, 2, 3] जैसे square brackets से लिखा जाता है।

क्योंकि lists insertion order को सुरक्षित रखती हैं और duplicates की अनुमति देती हैं, जब भी आपको सामान्य-उद्देश्य वाला sequence चाहिए, ये डिफ़ॉल्ट पसंद हैं।

उदाहरण: Lists

python
numbers = [1, 2, 2, 3]  # list can hold duplicate values
numbers.append(4)  # add an item to the end of the list
print(numbers)

Dictionaries

dict अद्वितीय keys को values से {key: value} syntax के ज़रिए जोड़ता है, जिससे list को एक-एक item करके खंगालने के बजाय key से लगभग तुरंत lookup मिलता है।

जब आपका data स्वाभाविक रूप से जोड़ियों के रूप में वर्णित हो, जैसे किसी username का user record से जुड़ना, तब dictionaries सबसे उपयुक्त हैं।

उदाहरण: Dictionaries

python
user = {"name": "Alex", "age": 30}
print(user["name"])
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.