Python Character Classes

Python में regular expression ये string पर operation करता है |


नमस्कार दोस्तो आज इस आर्टिकल में जानेंगे कि mathematics python क्या हैं ? और यह कितने प्रकार के होते हैं ? Python में numbers पर mathematical operations करने के लिए math functions का इस्तेमाल किया जाता है | Python के program में अगर math functions का इस्तेमाल करना हो तो 'math' module का इस्तेमाल किया जाता है |
| Math Constant | Description |
|---|---|
| e | Math की 'E' Property Euler का number return करता है | |
| inf | infinity को return करता है | |
| nan | not a number(nan) का वर्णन करता है | |
| pi | pi की value को return करता है | |
| tau | tau(τ) की value को return करता है | |

नमस्कार दोस्तो आज इस आर्टिकल में जानेंगे कि Python में datetime module क्या हैं ? और यह कितने प्रकार के होते हैं ? हर एक Programming Language में Date और Time का concept होता है | Python में भी Date और Time का concept होता है | Date और time के लिए कुछ modules को import करना पड़ता है | वैसे ही कुछ Modules नीचे दिए गए है |
time module पे बहुत सारे date और time से related functions, classes और constants होते है |
datetime module में भी constants, classes; date और time से related होते है | ये module date और time के साथ काम करने के लिए Object-Oriented Programming में बनाया गया है |
Calendar module में calendar से related कुछ functios और classes होते है |
12.00am January 1, 1970 से अबतक के बीते हुए seconds को 'Ticks' कहते है |
Python में 12.00am January 1, 1970 से अबतक के बीते हुए seconds को return करने के लिए time module में 'time()' ये function होता है | ये time() function बीते हुए seconds को floating-point number में return करता है |
import time
print("Timestamp/ticks :",time.time())
#Output :
#Timestamp : 1497628217.2675047import time
print("epoch :",time.gmtime(0))
Output :epoch :
time.struct_time(
tm_year=1970,
tm_mon=1,
tm_mday=1,
tm_hour=0,
tm_min=0,
tm_sec=0,
tm_wday=3,
tm_yday=1,
tm_isdst=0)

Python Function ये statements का एक समूह होता है | हर एक Program में एक function तो होता ही है| जहाँ पर Function की statements की जरुरत होती है वहाँ पर Function को call किया जाता है |
Function में लिखा हुआ code बार-बार लिखना नहीं पड़ता |
बड़े Program को छोटे-छोटे function में विभाजित किया जा सकता है |
Function Programmer का समय, Program की space और memory बचाता है |
अगर Program में कहा पर error आ जाए तो उसे आसानी से निकाला जा सकता है |
जहाँ पर जरुरत हो वहाँ पर function को बार-बार call किया जा सकता है |
Python में अभीतक print() नामक function बहुत ही बार इस्तेमाल किया है | print() function ये Python में in-built function है |
Python में user-defined function में दो प्रकार पड़ते है | Function Definition Function Call
def function_name(parameter(s)):
"function_docstring"
function_body
return statementdef : Python में function को create करना हो तो शुरुआत में 'def' keyword का इस्तेमाल किया जाता है |
function_name : def keyword के बाद function का नाम दिया जाता है | हर function का नाम उसके statement से related हो तो अच्छा रहता है |
(parameter(s)) : Optional. parameters optional होते है parenthesis(()) नहीं होते है | function के name के बाद parenthesis(()) दिया जाता है | उन parenthesis में एक या एक से ज्यादा parameters दिए जाते है | parameters; optional होते है |
: : parenthesis के बाद colon(:) देना अनिवार्य होता है | colon देने के बाद Python interpreter द्वारा automatic code indent होता है |
"function_docstring" : Optional. यहाँ पर documentation string दिया जाता है |
function_body : Optional. ये function की body होती है | जिसमे कुछ local variables और statements हो सकते है | body में दिए हुए variables को global भी बनाया जा सकता है |
return statement : Optional. ये return statement होता है | return statement के लिए 'return' keyword का इस्तेमाल किया जाता है | ये statement से function end होता है | अगर return statement दिया नहीं जाता है तो default 'None' return होता है |
Example for Function Definition
#Function definition
def func(param): #function name, parameter and colon
"This is a docstring" #docstring
print(func.__doc__) #function body
return param #return statementExample पर 'func' ये function का नाम है |
उसके बाद parenthesis(()) में 'param' नाम का एक parameter और parenthesis के बाहर colon(:) दिया गया है |
function के indent code में पहले docstring दी गयी है |
उसके बाद function की body में class attribute की मदद से docstring को print किया गया है और आखिर में return statement में 'param' इस parameter को print किया गया है |
Function के call में सिर्फ function का नाम और अगर function को parameter हो तो parameter की value दी जाती है | जबतक function को call नहीं किया जाता तबतक function का code execute नहीं होता है |
Example for Function Call
#Function definition
def func(param): #function name, parameter and colon
"This is a docstring" #docstring
print(func.__doc__) #function body
return param #return statement
print("Call 1")
print(func(5)) #Function call
print("Call 2")
print(func(10)) #Function call
Output :Call 1
This is a docstring
5
Call 2
This is a docstring
10Python में जब function को call करके जिस data type की value as a argument दी जाती है तब उसका data type decide हो जाता है |
Python में चार प्रकार के function parameter होते है |
Default argument में definition पर argument के लिए default value '='(assignment operator) से set की जाती है |
Function Call पर जब definition पर assign किया हुआ argument नहीं दिया जाता तो default value pass की जाती है |
def DefArg(num=5, str="Hello"):
print(num)
print(str)
print("Call1")
DefArg()
print("Call2")
DefArg(8)
print("Call3")
DefArg(8, "Hii")
Output :Call1
5
Hello
Call2
8
Hello
Call3
8
HiiRequired Argument में function call पर argument देना अनिवार्य होता है |
जब function definition पर argument दिया जाता है तब उसे function call पर उसकी value देना required होता है |
def ReqArg(num, str):
print(num)
print(str)
print("Call1")
ReqArg(5, "Hello World")
print("Call2")
ReqArg("Hello World", 5)
Output :Call1
5
Hello World
Call2
Hello World
5अगर function call पर argument दिया नहीं जाता है तो , TypeError का exception आ जाता है |
अगर function पर दो arguments है | अगर call करते वक्त एक ही argument value दी जाती है तो तब भी 'TypeError' exception आ जाता है |

Programming भाषा में, प्रोग्राम के execution के flow को नियंत्रित करने के लिए जो स्टेटमेंट्स या structures प्रयोग किये जाते है उन्हें control statements(structures) कहते है|
Python में if, if_else और if_elif_else ये तीन प्रकार के Control Statements होते है |
इन control statements से जब तक दिया हुआ expression true नहीं होता तब तक ये अपना statement; execute नहीं होता है |
if Statement में जब expression true होता है तब वो अपने statement को execute होता है और अगर expression false होता है तब वो execute नहीं होता है |
if expression :
if_statement(s)
Example for if Statement
Source Code :a = 2
b = 3
if(a < b) :
print("a is less than b")
Output :a is less than bPython में if, if_else और if_elif_else ये तीन प्रकार के Control Statements होते है |
इन control statements से जब तक दिया हुआ expression true नहीं होता तब तक ये अपना statement; execute नहीं होता है |
if Statement में जब expression true होता है तब वो अपने statement को execute होता है और अगर expression false होता है तब else का statement; execute होता है |
if expression :
if_statement(s)
else :
else_statement(s)
Syntax for if_else Statement
Source Code :a = 2
b = 2
if(a < b) :
print("a is less than b")
else :
print("a is greater than or equal to b")
Output :a is greater than or equal to bPython में if, if_else और if_elif_else ये तीन प्रकार के Control Statements होते है |
इन control statements से जब तक दिया हुआ expression true नहीं होता तब तक ये अपना statement; execute नहीं होता है |
if Statement में जब expression true होता है तब वो अपने statement को execute होता है और अगर expression false होता है तब flow elif पर जाता है अगर elif का expression; true होता है तो उसका statement execute होता है और elif का expression; false होता है तब else का statement execute होता है |
if expression :
if_statement(s)
elif expression :
elif_statement(s)
else :
else_statement(s)
Syntax for if_else Statement
Source Code :a = 2
b = 2
if(a < b) :
print("a is less than b")
elif(a > b) :
print("a is greater than b")
else :
print("a is equal to b")
Output :a is equal to bpass Statement ये null Statement होता है | जब pass Statement execute होता है तब कुछ नहीं होता है |
Program में जब functions, loops, classes या control statement लिखा जाता है उनकी body उसके निचे ही लिखी जाती है लेकिन अगर उनकी body बाद में लिखनी हो तो 'pass' Statement का इस्तेमाल किया जाता है |
pass
Example for pass Statement
Source Code :class A: pass
def func(param):
pass
func(10)
print("Hello World")
Output :Hello WorldPython में break Statement Loop को किसी expression पर बंद कर देता है |
breakExample for break Statement Example में अगर 'n' को 4 मिल जाता है तब for Loop का iteration बंद हो जाता है |
nums = [1, 2, 3, 4, 5]
for n in nums :
print(n)
if(n == 4):
break
Output :1
2
3
4continue Statement से Loop में iterate हो रहे कुछ statement(s) को skip करके अगले statements को execute करता है |
continue
Example for continue Statement
Source Code :nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
for n in nums :
if(n == 5) :
print("Skipped Element :", n)
continue
print(n)
Output :1
2
3
4
Skipped Element: 5
6
7
8
9
10
सभी प्रोग्रामिंग लैंग्वेज ( जैसे की C++ , java आदि ) में हमें loops की सुविधा प्रदान की जाती है उसी प्रकार पाइथन लैंग्वेज मे भी loops का उपयोग किया जाता है | Loops का उपयोग कोड को बार बार execute करने के लिए होता है|
जैसे की हमे किसी कोड या फंक्शन को 200 से ज्यादा बार execute करना है तो हमे इस कोड को उतनी ही बार कॉल करना पड़ेगा या लिखना पड़ेगा जितनी बार कोड को execute करना है इस प्रोसेस मे हमे कोड को लिख़ने मे ज्यादा समय लग जाता है |
इस प्रॉब्लम को दूर करने के लिए हम लूप्स का प्रयोग करते है | लूप्स के द्वारा हम जितनी बार चाहे उतनी बार प्रोग्राम को execute करा सकते है | इससे हमे कोड को बार बार कॉल करने की जरूरत नहीं पड़ती |
loops मे हम condition का उपयोग करते है जिससे की हम लूप्स को start और end करा सकते है | लूप्स मे अगर हमारी कंडीशन true होती है तो code / loops execute होता रहेगा जैसे की कंडीशन false होती है कोड terminate हो जाता है
पाइथन मे तीन प्रकार के लूप्स होते हैं |
while लूप को हम आसानी से define कर सकते है | ये एक simple लूप है | While loop, दी गई शर्त जब तक TRUE है, तब तक यह स्टेटमेंट्स (कोड) को लगातार execute करता है। यह पहले condition को check करता है और फिर instruction देता है|
Syntax for while loop in pythonwhile (expression): while_statement(s)
उदहारण :- यदि हमें hello word को 10 बार प्रिंट कराना है तो इसे दो तरीके से सकते हैं | 1. पहला या तो हम 10 बार hello word को लिख कर प्रिंट कराये | जिससे की प्रोग्राम काफी बड़ा हो जायेगा | २. दूसरा हम loop का प्रयोग करके hello word को print करे | जिससे प्रोग्राम काफी सरल हो जायेगा | हम अब देख़ते है की लूप द्वारा हम कैसे hello word को 10 बार print करेंगे |
i= 1
while i<=10:
print ("hello word")
i=i+1for < Variable_Name > in < Sequence_Name >
statementsउदहारण :- ऊपर दिए गए उदहारण को हम for loop के सहायता से 10 बार प्रिंट कराएँगे |
for i in range (10):
print ("hello word !")Step 1:- सबसे पहले हम for कीवर्ड को लिख़ते है | step 2:- फिर वेरिएबल का नाम लिख़ते है जो की sequence को iterate करेगा | step 3:- फिर in ऑपरेटर को लिख़ते है | step 4:- उसके बाद हम sequence का नाम लिखेंगे जिसको iterate करना है | step 5:- फिर हम statement लिखेंगे जो हमें प्रिंट करनी है | break and continue keyword break keyword का प्रयोग हम लूप को ख़त्म करने लिए करते हैं |
for i in range (1 , 11):
if i==5:
break
print (i)Output :
1 2 3 4
ऊपर दिए गए example मे जब i == 5 होगा तो लूप ब्रेक हो जायेगा ओर हमे ऊपर दिया गया आउटपुट मिलेगा | continue keyword , loopके current iteration को stop करता है ओर फिर continue आगे बढ़ता है |
for i in range (1 , 11):
if i==5:
continue
print (i)Output:
1 2 3 4 6 7 8 9 10
ऊपर दिए गए example मे जब i == 5 होगा तो current iteration stop हो जायेगा ओर हमे ऊपर दिया गया आउटपुट मिलेगा | nested loop in python पाइथन मे भी हम बाकि प्रोग्रामिंग लैंग्वेज की तरह एक लूप के अंदर दूसरा लूप define कर सकते हैं |
for i in range(1, 4):
for j in range(i):
print(i, end=' ')
print() Output :
1 2 2 3 3 3
अगर आपको यह पोस्ट 📑 (Loops In Python In Hindi)पसंद आई हो तो अपने मित्रों के साथ जरूर शेयर करें। धन्यवाद !
-min.jpg)
Python में input/output के लिए कुछ functions का इस्तेमाल किया जाता है | User के keyboard से input लेने के लिए 'input()' इस function का इस्तेमाल किया जाता है और User के screen पर कुछ print करने के लिए 'print()' इस function का इस्तेमाल किया जाता है |
input() Function for taking User Input Python में जब User से कुछ letters या numbers लेने की बारी आती है तब 'input()' function का इस्तेमाल किया जाता है |
Syntax for input() Function
input("SomeText")Some Text : Optional.User को क्या input देना है उसके बारे में यहाँ पर कुछ text दिया जाता है | Example for 'input()'
Function Source Code :
a = input("Enter your name : ")
print("Your name is", a)
Output :Enter your name : Maxon Your name is Maxon
जब User; numeric, letters या special symbols; input लेते है तो उसका data type 'string' होता है |
Source Code :
a = input("Enter Number : ")
print("Entered input's type is", type(a))
Output :Enter Number : 4 Entered input's type is
जब उस String data type को Number(int, float, complex number) में convert करना हो तो Type Conversion functions का इस्तेमाल करना पड़ता है |
Source Code :
a = input("Enter Number : ")
print("Entered input's type is", a)
b = int(a)
print("Entered input's type is", b)
print("Entered input's type is", type(b))
c = float(a)
print("Entered input's type is", c)
print("Entered input's type is", type(c))
d = complex(a)
print("Entered input's type is", d)
print("Entered input's type is", type(d))
Output :Enter Number : 4 Entered input's type is 4 Entered input's type is 4 Entered input's type is Entered input's type is 4.0 Entered input's type is Entered input's type is (4+0j) Entered input's type is
अभी तक User के screen पर output दिखाने के लिए 'print()' function का इस्तेमाल किया गया था, लेकिन print() function के लिए एक से ज्यादा parameters होते है | जिनका इस्तेमाल एक से ज्यादा newline देना या file handling के लिए किया जाता है |
Regular Example for print() Function
a = 5
print("Value of a is", a) #Output : Value of a is 5
Syntax for print() Functionprint(value1,value2,...,valueN, sep="", end="\n", file=sys.stdout, flush=False)
value1,value2,...,valueN, :
यहाँ पर एक या एक से ज्यादा values दी जाती है | हर value को comma(,) से seperate किया जाता है |
Optional. जब एक से ज्यादा values दी जाती है तो default 'sep' parameter द्वारा space( ) दिया जाता है | User चाहे तो 'sep' parameter पर कोई भी value दे सकता है |
Optional. 'end' parameter पर '\n'(newline) default दिया जाता है | User चाहे तो 'end' parameter पर कोई भी value दे सकता है |
Optional. 'file' parameter पर 'sys.stdout'(print entered text on screen) default दिया जाता है | User चाहे तो 'file' parameter पर किसी भी file को open कर सकता है |
Optional. 'flush' parameter पर 'False' ये value default होती है | जब False दिया जाता है तब stream को flush नहीं किया जाता है या जब 'True' दिया जाता है तब stream को जबरन flush किया जाता है |
print() function null/None return करता है |
Example for print() Function with 'sep' Parameter Example पर '!!!!!' इस string से separate किया गया है |
Source Code :
print("Hello World", "Hello Friends", "Hello Maxon", sep="!!!!!")
Output :Hello World!!!!!Hello Friends!!!!!Hello Maxon
Example में end पर '\n\n\n\n\n' इस string दिया गया है |
Source Code :
print("Hello World", end="\n\n\n\n\n")
print("Hello Friends")Output :
Hello World Hello Friends
Example पर print() function के 'file' parameter द्वारा 'textfile.txt' इस file पर 'Hello World' ये string write किया गया है |
Source Code :
f = open("textfile.txt", "w")
print("Hello World", file = f)
f.close()
textfile.txtHello World
Note : print() function में binary files पर operation नहीं किया जाता है | इसके बदले में write() function का इस्तेमाल किया जाता है |
अगर आपको यह पोस्ट 📑 (Python Input Output In Hindi)पसंद आई हो तो अपने मित्रों के साथ जरूर शेयर करें। धन्यवाद !

Operator एक symbol है जो कि एक ऑपरेशन को प्रस्तुत करता है| और वह वैल्यू जिस पर ऑपरेटर कार्य (operate) करते है उन्हें operands कहते है|
Operators का प्रयोग प्रोग्राम में data तथा variables को manipulate करने के लिए किया जाता है| अर्थात् operators वो symbols होते है जिनका प्रयोग प्रोग्राम में गणितीय या लॉजिकल ऑपरेशन करने के लिए किया जाता है|
python operators दो प्रकार के होते है:-
unary operator केवल एक operand पर operate होता है|
binary operator दो operands पर operate होता है|
उदाहरण के लिए:- 4+6, जहाँ 4 तथा 6 operands है जबकि + एक ऑपरेटर है.
python operators निम्नलिखित होते है:-
1:- arithmetic operator
2:- relational (comparison) operator
3:- logical operator
4:- bitwise operator
5:- assignment operator
6:- identity operator
7:- membership operator
arithmetic operators का प्रयोग गणितीय कार्यों को करने के लिए किया जाता है |
जैसे:- addition, subtraction, division आदि|
यहाँ पर हमने उदाहरण के लिए वेरिएबल x का मान 20 तथा y का मान 30 लिया है|
| operators | description | उदाहरण |
|---|---|---|
| + (addition) | यह दो operands को जोड़ता है. | x + y = 50 |
| – (substraction) | यह दो operands को घटाता है. | x – y = -10 |
| * (multipication) | यह दो operands को गुणा करता है | x * y = 600 |
| / (division) | यह right वाले operands से left वाले operands को divide करता है | y / x = 1.5 |
| % (modulus) | यह right वाले operand से left वाले operand को divide करता है तथा यह शेषफल return करता है. | y * x = 0 |
| // (floor division) | यह right वाले operands से left वाले operands को divide करता है तथा भागफल return करता है. यह दशमलव वाले हिस्से को छोड़ देता है | जैसे:- 13//3 = 4 तथा 15//2 = 7 |
| ** (exponential) | इसमें right वाला operand, left वाले operand की power (घात) बन जाता है. | x ** y (x to the power y) माना x = 2, y =4 तो x ** y = 16 |
रिलेशनल ऑपरेटर का प्रयोग दो values को compare करने के लिए किया जाता है|
यह condition के अनुसार या तो true या false return करता है |
यहाँ पर हमने उदाहरण के लिए वेरिएबल x की वैल्यू 20 तथा y की वैल्यू 30 दी है|
| operators | description | उदाहरण |
|---|---|---|
| == | यदि दोनों operands की वैल्यू समान होती है तो condition सत्य होती है. | (x == y) सत्य नहीं है. |
| != | यदि दोनों operands की वैल्यू समान नहीं होती है तो condition सत्य होती है. | (x != y) सत्य है |
| < > | यदि दोनों operands की वैल्यू समान नहीं होती है तो condition सत्य होती है. यह != की तरह है. | (x < > y) सत्य है |
| > | यदि left operand की वैल्यू right operand से बड़ी होती है तो condition सत्य होती है. | (x > y) सत्य नही है. |
| < | यदि right operand की वैल्यू left operand से बड़ी होती है तो condition सत्य होती है. | (x < y) सत्य है. |
| >= | यदि left operand की वैल्यू right operand से बड़ी होती है या बराबर होती है तो condition सत्य होती है | (x >= y) सत्य नही है. |
| <= | यदि right operand की वैल्यू left operand से बड़ी होती है या छोटी होती है तो condition सत्य होती है | (x <= y) सत्य है. |
लॉजिकल ऑपरेटर वह है जो Boolean expressions को compare करता है तथा Boolean result रिटर्न करता है|
| operators | description | उदाहरण |
|---|---|---|
| and | यदि दोनों operands सत्य होते है तो condition सत्य होती है. | 6>3 and 5<10 सत्य है |
| or | यदि दो operands में से एक भी सत्य होता है तो condition सत्य होती है. | 6>3 or 5>10 सत्य है |
| not | यदि operands की वैल्यू गलत होती है तो condition सत्य होती है. | not(5 < 2) सत्य है |
bitwise python operators वह हैं जो bits पर कार्य करते हैं तथा bit by bit ऑपरेशन को परफॉर्म करते हैं|
उदाहरण के लिए माना x = 10 तथा y = 4 तो बाइनरी फॉरमेट में x = 0000 1010 तथा y = 0000 0100
| operators | meaning | उदाहरण |
|---|---|---|
| & | bitwise AND | x & y = 0 (0000 0000) |
| | | bitwise OR | x | y = 14 (0000 1110) |
| ~ | bitwise NOT | ~ x = -11 (1111 0101) |
| ^ | bitwise XOR | x ^ y = 14 (0000 1110) |
| >> | Bitwise right shift | x >> 2 = 2 (0000 0010) |
| << | Bitwise left shift | x << 2 = 40 (0010 1000) |
python में assignment operators का प्रयोग variables को वैल्यू assign करने के लिए किया जाता है|
| operators | description | उदाहरण | same as |
|---|---|---|---|
| = | यह बायीं तरफ के expression को वैल्यू assign करता है. | x = 5 | x = 5 |
| += | यह right operand को left operand से जोड़ता है तथा जो result आता है उसे left operand को assign करता है. | x += 5 | x = x + 5 |
| -= | यह right operand को left operand में घटाता है तथा जो result आता है उसे left operand को assign करता है. | x -= 5 | x = x – 5 |
| *= | यह right operand को left operand में गुणा करता है तथा जो result आता है उसे left operand को assign करता है. | x *= 5 | x = x * 5 |
| /= | यह left operand को right operand से divide करता है तथा जो result आता है उसे left operand को assign करता है. | x /= 5 | x = x / 5 |
| %= | यह दो operands का modulus लेता है और उसे left operand को assign करता है. | x %= 5 | x = x % 5 |
| **= | यह operands में power (घात) को परफॉर्म करता है तथा उसे left operand को assign करता है. | x **= 5 | x = x ** 5 |
| //= | यह operators में floor division को परफॉर्म करता है तथा उसे left operand को assign करता है. | x //= 5 | x = x // 5 |
identity python operators दो ऑब्जेक्ट्स के मैमोरी लोकेशन को compare करता है|
| operators | description | उदाहरण |
|---|---|---|
| is | यदि दोनों operands एक ही जैसी identity साझा करते है तो condition सत्य होगी अन्यथा असत्य होगी. | x is y |
| is not | यदि दोनों operands एक ही जैसी identity साझा नहीं करते है तो condition सत्य होगी अन्यथा असत्य होगी. | x is not y |
membership python operators का प्रयोग sequence में membership को टेस्ट करने के लिए किया जाता है|
sequence एक list, एक string या एक tuple हो सकती है|
python में दो मेम्बरशिप ऑपरेटर है जो नीचे दिए गये है|
| operators | description | उदाहरण |
|---|---|---|
| in | यदि ऑपरेटर के दोनों तरफ के वेरिएबल एक sequence में होते है तो condition सत्य होगी अन्यथा असत्य होगी. | x in y |
| not in | यदि ऑपरेटर के दोनों तरफ के वेरिएबल एक sequence में नहीं होते है तो condition सत्य होगी अन्यथा असत्य होगी. | x not in y |

Python में Code indentation को काफी महत्व दिया गया है | Python में Code Indentation का इस्तेमाल functions, classes, Loops और control statements के लिए किया जाता है |
Python में curly braces({}) की जगह code indentation का इस्तेमाल किया जाता है |
Python में जब code indentation में colon(:) या delimiter दिया जाता है तब automatically अगले line पर interpreter द्वारा tab( ) दिया जाता है |
Source Code :
def func():
a = 5
print(a)
func()Output :
5Source Code :
list = [1, 5, 8, 9]
for i in list:
print(i)Output :
1
5
8
9Source Code :
class myClass:
def func():
a = 5
print(a)
myClass.func()Output :
5अगर आपको यह पोस्ट 📑 (Python Indenting Code In Hindi)पसंद आई हो तो अपने मित्रों के साथ जरूर शेयर करें। धन्यवाद !

नमस्कार दोस्तो आज इस आर्टिकल में जानेंगे कि Python में Data Types क्या हैं ? और यह कितने प्रकार के होते हैं ?
Python में variables के अन्दर अलग-अलग types की values store की जाती है जैसे कि किसी variable के अन्दर numeric value तो किसी दूसरे variable के अन्दर alphabetic value store की जाती है, इसे ही 'Data Types' कहा जाता है |
सभी programming language में डाटा टाइप होते हैं |
इसी प्रकार पाइथन में भी कुछ डाटा टाइप (python data types) हैं जो की इस प्रकार हैं |
Note : type() function का इस्तेमाल data type check करने के लिए किया जाता है |
Number Data Types के तीन प्रकार होते है |
Integer data type ये normal numeric values होती है | integer numbers को अपूर्णांकित हिस्सा नहीं होता है |
Floating-point numbers को अपूर्णांकित हिस्सा होता है | Python में floating-point number के लिए कोई मर्यादा नहीं होती है |
Complex data type 'a + bj' इस form में होता है इसमे 'a' ये real part होता है और 'b' ये imaginary part होता है |
# यह Integer data type है |
a = 5
b = 12545885
c = 412154986446513513878678541351865465
print(a)
print(b)
print(c)
print(type(a))
print(type(b))
print(type(c))
# यह Floating-point numbers data type है |
a = 5.0
b = 12545885.568444444444445
c = 412154986446513513878678541351865465.4547878541516546845
print(a)
print(b)
print(c)
print(type(a))
print(type(b))
print(type(c))
# यह Complex data type है |
a = 1 + 4j
b = 5 + 4758499j
print(a)
print(b)
print(type(a))
print(type(b))
Output :#Integer data type
5
12545885
412154986446513513878678541351865465
#Floating-point Number Data Type
5.0
12545885.568444444
4.121549864465135e+35
#Complex data type
(1+4j)
(5+4758499j)String ये characters का set होता है | characters; letters, numbers या special symbols हो सकते है| Python में single(' ') या double(" ") quotes के अन्दर लिखे जाते है | String ये immutable data type है |
str1 = "Hello World"
str2 = "Hello Friends"
print(str1)
print(str2)
Output :Hello World
Hello Friendsज्यादातर Programming languages में string को index में print किया जाता है उसी प्रकार से Python में भी string को indexes से print किया जाता है | string के सबसे पहले character को index '0' से शुरू होती है और string के सबसे आखिरी index '-1' होती है |
Python के list data type में एक से ज्यादा items होते है | हर एक item को comma(,) से separate किया जाता है |
list के सभी items को square bracket([]) के अन्दर close किये जाता है |
List ये एक compound data type है जिसमे किसी भी data types के items लिए जा सकते है | list ये एक mutable data type है | इन data type के items की values change की जा सकती है |
list = [1, "Hello", 5.6, (1, "MAXON")]
for i in list:
print(i)
Output :1
Hello
5.6
(1, 'MAXON')Python के list data type में एक से ज्यादा items होते है | ये list data type के जैसे ही होता है | हर एक item को comma(,) से separate किया जाता है |Tuple के सभी items को parenthesis(()) के अन्दर close किये जाता है |
Tuple ये एक compound data type है जिसमे किसी भी data types के items लिए जा सकते है | list ये एक immutable data type है | इन data type के items की values change नहीं की जा सकती है |
tuple = (1, "Hello", 5.6, (1, "MAXON"))
for i in tuple:
print(i)
tuple[0] = 3 #trying to changing 0th index
print(tuple[0])
Output :1
Hello
5.6
(1, 'MAXON')
Traceback (most recent call last):
tuple[0] = 3 #trying to changing 0th index
TypeError: 'tuple' object does not support item assignmentData Type में keys और values की pairs होती है | हर key value के pair को comma(,) से और key और value को colon(:) से separate किया जाता है |
Dictionary के सभी keys और values को curly braces({}) में लिखा जाता है | ये एक immutable data type है |
dict = {1:"H", 5:"e", 7:"l", 8:"l", 9:"o"}
print(dict[5])
print(dict[9])
Output :e
oSet Data Type ये items का unordered collection होता है | set में दिए हुआ हर एक item नया होता है | अगर duplicate item मिल जाता है तो उसे remove किया जाता है |
set data type के items को curly braces({}}) के अन्दर लिखा जाता है |
set1 = {"Maxon", "Puneet", "Kapil"}
for i in set1:
print(i)
set2 = {3, 5, 8, 7, 1, 3}
for j in set2:
print(j)
Output :