Python Data Types
In this page:
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
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
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
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
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
user = {"name": "Alex", "age": 30}
print(user["name"])
Chapter Quiz — Complete all 14 topics to unlock
0/14 topics done
Complete these topics first: