Posts

Python | File Handling & It's Types By. Shivansh Sir

PYTHON   PROGRAMMING PYTHON | FILE HANDLING जब Computer पर कोई data लिखा जाता है तब वो पहले अपने RAM(Random Access Memory) पर store होता है और जब Computer को turn off किया जाता है तब वो सारा data lose हो जाता है |  और जब उस data को save किया जाता है तब वो Computer के Secondary Storage Device(Hard Drive) पर permanently store किया जाता है | PYTHON |  FILE HANDLING | OPENING A FILE   File के data को जब manipulate करना हो तो पहले file को open किया जाता है |  Python में file को open करने के लिए python के in-built 'open()' method का इस्तेमाल किया जाता है | Syntax for open() Method fileObj = open(fileName, mode) Parameters : open() method के लिए 8 parameters होते है लेकिन यहाँ पर सिर्फ 2 महत्वपूर्ण parameters दिए गए है | fileName : यहाँ पर file name के साथ उसका extension भी दिया जाता है | अगर same location पर file हो तो उसे path देने की जरुरत नहीं होती है | mode : यहाँ पर file को open करने के लिए mode दिया जाता है | अगर mode दिया नहीं जाता है तो default 'r'(reading) mo...

Python | Modules & It's Types By. Shivansh Sir

   PYTHON   PROGRAMMING PYTHON | MODULES & IT'S TYPES Python में कुछ inbuilt Modules होते है जैसे कि , math, random | हर module की अलग-अलग पहचान होती है | math module में mathematics से related कुछ functions होते है जैसे कि, sin(), cos() और sqrt() इत्यादी |  Python में Modules ये एक तरह का program ही होता है | modules में function और classes होते है | Python में दो प्रकार के Modules होते है | In-built Modules User-Defined Modules 1. In-built Modules Python में 350+ Modules होते है | ये modules अलग-अलग काम के लिए बने होते है |  Python के सभी in-built modules देखने के लिए , help("modules") 2. User-Defined Modules PYTHON |  MODULES |  USER DEFINED | CREATION एक program दिया गया है | उसके file का नाम 'arithmetic.py' है | जो नाम file का होता है वही नाम 'module' का होता है | 'arithmetic' module में add, sub, mul और div नाम के functions दिए गए है | Source Code  File Name : arithmetic.py def add(a, b):     return a + b def sub(c, d):  ...

Python | Inheritance, Multi-Level Inheritance & Multiple Inheritance By. Shivansh Sir

  PYTHON   PROGRAMMING PYTHON | INHERITANCE Inheritance OOP(Object-Oriented Programming) का एक हिस्सा है | Inheritance में एक से ज्या classes होते है | Inheritance में दो प्रकार के मुख्य class देना अनिवार्य होता है | Base Class (Parent) : Base class को super या parent class भी कहा जाता है | Derived Class (Child) : Derived class को sub या child class भी कहा जाता है | Derived class ये Base class की properties या attributes को inherit करता है | Syntax class Base: "This is a Docstring(Optional)" Base_Class_Body class Derived (Base): "This is a Docstring(Optional)" Derived_Class_Body Example Example पर Fitness Class के obj इस object से Employee Class की properties को inherit किया गया है | Source Code  class Employee: "Class Employee"     def set1(self,empid,name,salary):                 self.empid = empid         self.name = name         self.salary = salary class Fitness(...

Python | Function & Their Types By. Shivansh Sir

  PYTHON   PROGRAMMING PYTHON | FUNCTION Python Function ये statements का एक समूह होता है | हर एक Program में एक function तो होता ही है | जहाँ पर Function की statements की जरुरत होती है वहाँ पर Function को call किया जाता है | PYTHON |  FUNCTION | FEATURES Function में लिखा हुआ code बार-बार लिखना नहीं पड़ता | बड़े Program को छोटे-छोटे function में विभाजित किया जा सकता है | Function Programmer का समय, Program की space और memory बचाता है | अगर Program में जहा पर error आ जाए तो उसे आसानी से निकाला जा सकता है | जहाँ पर जरुरत हो वहाँ पर function को बार-बार call किया जा सकता है | PYTHON |  FUNCTION |  TYPES OF FUNCTION 1. In-Built/Predefined Function Python में  print() function बहुत ही बार इस्तेमाल किया है | print() function ये Python में in-built function है | 2. User-Defined Function Python में user-defined function में दो प्रकार के होते है | 2.1 Function Definition Syntax for Function Definition def function_name(parameter(s)): "function_docstring" function_...

Python | Control Statements By. Shivansh Sir

   PYTHON   PROGRAMMING PYTHON |  STATEMENT | IF STATEMENT Python में if, if_else और if_elif_else ये तीन प्रकार के Control Statements होते है |  इन control statements से जब तक दिया हुआ expression true नहीं होता तब तक ये अपना statement; execute नहीं होता है | if Statement में जब expression true होता है तब वो अपने statement को execute होता है और अगर expression false होता है तब वो execute नहीं होता है | Syntax for if Statement 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 b PYTHON |  STATEMENT |  IF ELSE STATEMENT Python में if, if_else और if_elif_else ये तीन प्रकार के Control Statements होते है | इन control statements से जब तक दिया हुआ expression true नहीं होता तब तक ये अपना statement; execute नहीं होता है | if Statement में जब expression true होता है तब वो अपने statement को execute होता है और अगर expression false होता है ...

Python | Loop | For Loop By. Shivansh Sir

PYTHON   PROGRAMMING PYTHON |  LOOP | FOR LOOP Loop का इस्तेमाल sequence के elements को iterate करने के लिए किया जाता है |  for Loop का इस्तेमाल कोई भी sequence के सभी elements को display करने के लिए किया जाता है |  sequence ये list, tuple, dictionary और string होता है | Syntax for variable in sequence for_statement(s) जब iteration शुरू होता है तब variable पर sequence का element assign किया जाता है और दिए गए statement को execute किया जाता है | जितने elements की संख्या होती है उस संख्या तक iteration होता रहता है और उसके बाद loop का control loop के बाहर आ जाता है | Example  for Iterating List Sequence Source Code a = [5, 6, 9, 8, 5, 7] for n in a :     print(n) Output 5 6 9 8 5 7 Example for Iterating Tuple Sequence Source Code tuple = (1, 2, [3, 4, 5], 6, 7, 8) for a in tuple:     print(a) Output 1 2 [3, 4, 5] 6 7 8 Example for Iterating Dictionary Sequence Source Code dict = {1:6, 2:5, 3:3, 4:8, 5:4, 6:2, 7:5, 8:4, 9:11, 12:45 } for a in di...

Python | Loop | While Loop By. Shivansh Sir

PYTHON   PROGRAMMING PYTHON |  LOOP | WHILE LOOP Loop एक ही statement को बार-बार execute करता है | Looping में indentation का काफी महत्व होता है | While Loop का इस्तेमाल जब तक condition true होती है तब तक statement execute होता रहता है और जब condition false हो जाती है तब loop का iteration; stop हो जाता है | Syntax while (expression): while_statement(s) Example Source Code a = 0 while (a < 10) :     print("Value a is ", a)     a = a + 1 Output Value a is  0 Value a is  1 Value a is  2 Value a is  3 Value a is  4 Value a is  5 Value a is  6 Value a is  7 Value a is  8 Value a is  9 PYTHON | LOOP | WHILE LOOP | WITH ELSE STATEMENT While Loop के else का सम्बन्ध बनाया गया है | जब तक condition true होती है तब तक while loop का statement iterate होता रहता है और condition false होती है तब control pass होके else पर जाकर else का statement execute होता है | Source Code  a = 0 while(a < 5):     pri...