Python Programs में data types का क्या use होता है? – Data Types in Python in Hindi

Python Programs में data types का क्या use होता है -  Data Types in Python in Hindi
Python Programs में data types का क्या use होता है –  Data Types in Python in Hindi

Last tutorial में हमने Python Programs में variables का use कैसे करते है? सीखा था. इस tutorial में हम Python data types के बारे में बात करेंगे और समझेंगे की Python programs में data types का क्या use है.

Python programs में use होने वाली हर एक values (data) किसी ना किसी Python data type से belong करती हैं.

किसी भी value के data type से ये decide होता है उस value को आप अपने programs में कहाँ use कर सकते हो और उस values पर किस type के operations perform कर सकते हो.

(toc)

Data types के बारे में और आगे पढ़ने से पहले Python के बारे में आप ये बात हमेशा याद रखिएगा की Python एक highly object-oriented programming language हैं.

यहाँ मैंने highly शब्द का use इसलिए किया है क्योंकि Python programs में use होने वाले data types भी classes होते हैं और इन data types की जो values होती हैं उन्हें हम objects कहते हैं.

इसलिए अब जब भी हम किसी data type की बात करें तो समझ जाइएगा की हम किसी class की बात कर रहे हैं और जब values की बात करें तो समझ जाइएगा की हम objects की बात कर रहे हैं.

(ads)

अब अगर आप ये सोच रहे हो की Python में class और object क्या होता है तो ये आप हमारे आने वाले tutorials में detailed में पढ़ेंगे इसलिए अभी इन दोनों शब्दों पर बहुत ज्यादा ध्यान ना दें.

See also  Windows Computer या Laptop में Python install कैसे करते है? - How to Install Python on Windows in Hindi

Python Data Types कितने टाइप के होते हैं?

Python में भी बहुत तरह के data types होते हैं जिनकी list मैंने नीचे उनके use के हिसाब से अलग-अलग groups में categorize करके show की है.

  • Boolean Data Type – bool
  • Number Data Types – int, float, complex
  • Sequence Data Types – str (string), list, tuple
  • Set Data Types – set
  • Mapping Data Type – dict (dictionary)

जैसा की मैंने आपको ऊपर बताया की Python में data types भी classes ही होते हैं और इनकी values को हम objects भी कहते हैं.

Class और object के basis पर हम इन data types को ऊपर दी गयी categories की तरह 2 और types में divide करते हैं.

  • Mutable Data Types – list, dict, set
  • Immutable Data Types –  bool, int, float, complex, str, tuple

Mutable और immutable data types क्या है और इनमें क्या अंतर होता होता है ये आप हमारे data types के आगे वाले tutorials में समझ जाएंगे.

इस tutorial में हम सिर्फ bool, int, float और complex data types का use करना सीखेंगे और बाकी के data types (str,  list, tuple, set, dict) का use हम अलग-अलग tutorial में आगे सीखेंगे.

Python int data types

Int data type बिना decimals वाली integer values को represent करने के लिए किया जाता है और int data type की value कितनी बड़ी भी हो सकती है यानी इसकी कोई maximum limit नहीं है.

See also  C Programming में Recursion का use कैसे करते है? - Recursion in C Programming in Hindi

(ads)

जब भी आप अपने Python programs में किसी variables को कोई positive integer या negative integer या zero assign करते हो तब अपने आप उस variable का data type int set हो जाता है.

Example program:

Output:

15
-35
5675434753289

Python float data types

Float data types का उन positive या negative numbers को represent करता है जिनमें decimal numbers भी होते हैं.

इसके अलावा अगर floating numbers में ज्यादा digits होंगे तो उन numbers की short representation के लिए scientific notation का use किया जाता है.

Example program:

Output:

15.25
-35.145856
8566.56754347532
1.3537834386555454e+16

Python complex data types

जैसा की आपने maths में पढ़ा होगा complex number वो numbers होते हैं जिनमें read number के साथ-साथ imaginary number भी होता है.

Complex numbers को ज्यादातर a + bj की form में लिखा जाता है और इसमें a और b real numbers होते हैं और j imaginary number के तौर पर use होता है.

Python में complex numbers को represent करने के लिए complex data type का use होता है.

Example program:

Output:

(5+4j)

Python boolean data types

Python में boolean values True और False को represent करने के लिए हम bool data type का use करते हैं.

True और False दोनों constants values हैं और आप इन्हें अपनी expression में use कर सकते हो और किसी variables को भी assign कर सकते हो.

(ads)

Python programs में हम जहाँ भी boolean values का use करते हैं अगर आप वहां पर True या False की जगह किसी और data types की values use करते हो तो उन values को भी True या False की तरह ही treat किया जाता है.

See also  C Programming में String क्या होती हैं? - String in C Programming in Hindi

क्योंकि Python में 0 number, empty strings, empty list, empty tuple, empty set और empty dictionary को false की तरह और बाकी की सभी values को true की तरह treat किया जाता है.

Example program:

Output:

True
False
Hello
Hello

Explanation:

जैसा की मैंने आपको ऊपर बताया था की Python में लगभग हर values को True माना जाता है इसलिए जब line 9 पर हमने variable a (True) और variable d (1) को compare किया तो इस condition का result True आएगा.

क्योंकि value 1 को भी वहां पर True की तरह treat किया जाएगा और ऐसे ही line 14 पर जब हमने condition वाली जगह variable e (“HMT”) को use किया तो उसे भी True की तरह ही treat किया जाएगा. 

Python type() function

कभी-कभी हमें अपने Python programs में testing या किसी और कारण की वजह से हमें ये check करना होता है की हमारा variable का data type (class) क्या है और इसके लिए हम type() function का use करते हैं.

type() function syntax:

type(variable)

type() function example:

Output:

<class 'bool'>
<class 'int'>
<class 'float'>
<class 'complex'>

What’s Next: इस tutorial में हमने Python data types के basic को पढ़ा और Next tutorial में हम Python में data (values) input लेना और उन्हें print कराना सीखेंगे.

HTN

Hindi Tech News is a trusted technology website dedicated to delivering the latest tech updates in simple and easy Hindi. Our goal is to make technology understandable for everyone — beginners, students, tech lovers, and digital learners.

Related Articles

Back to top button