click below
click below
Normal Size Small Size show me how
Python
Python Concepts
| Term | Definition |
|---|---|
| Type Function | It returns what data type is in use |
| Assignment | The process of storing a value in variable |
| Expression | A combination of numbers,symbols or other variables that produce a result when evaluated. |
| variable name | Must start with letter doesn't use special character |
| Implicit Conversion | The interpreter automatically converts one data type in to another |
| None | Special data type in python, used to indicate that things are empty or they returned nothing |
| Function Advantages | They help to resue code againa and again in a script |
| Refactoring | Writing readable and under stable clean code |
| Object Oriented Programming | Object oriented programming is a paradigm , where real world concepts are defined and represented by Classes e.g. Fruits is class and then apple and orange instance of class.An idea is defind can be defined using class |
| Attributes of class | Attributes are characteristics associated to a type, e.g summer,winter or dry fruit |
| Methods of class | Functions associated with type, jesa k hum class fruit me aik function bnayen jis ka kam ho optimum temperature find krna fruit k liye |
| Special methods in class | Special methods are represnted by __(name)__ and python internally call them to use, e.g len function uses special method of __len__ |
| dir() function | print all the attributes and methods of an object |
| type() function | Ye btata hai k value ki class kiya hai. |
| type(" ") | Ye batye ga k ye string class hai |
| upper() method | Ye method kisi bhi string value ko capital letters me convert kr deta hai. |
| isnumeric() | Ye method humen sirf binary me answer return krta hai ,, check krny k bad k string numbers hai ya nhi |
| help() | Is function ki madad se hum tamam tafseelat maloom kr sakty hain kisi bhi class ki |
| instance of class | name = class () |
| Defining a class | class : color = "" flavour="" |
| setting a attribute of class | instancename.attribute = "value" |
| Dot Notaion | Dot notation is waja se hum class k kisi bhi method ya attribute tak ponch sakty hain aur uski value set kr sakty and retrieve bhi kr sakty |
| methods in class | Kisi bhi object se koi action , jesa k aik instance organe hai aur us se hum ny orange juice bnana hai to hum method use kren gy |
| method in class syntax | def func_name (self) ..................... return self |
| how to use attribute inside method | Attribute ko agr method k andar istimal krna hai to self.attribute likhna hoga |
| instance variable | instance variable wo hoty hain jinki value mukhtalif hoti hai different instance k liye |
| constructor method | In constructor method we define attributes inside method function , so that we dont forget what are the attirbutes of a class, we can create the instance and attribute write away |
| Syntax of constructor method | def __init__(self,color,flavor ): self. color = color self.flavor = flavour |
| instance using constructor method | jonnagold = Apple ("red", "Sweet") |
| when str method in class is useful | str method is useful, when you have need to print instance. def __str__(Self) retur "This apple is sweet " |
| Doc string | Doc string is brief text which explain what something does """" write what you want to explain |
| STDIN | I/O stream for input |
| STDOUT | I/O stream for output |
| STDERR | STDERR displays output specifically for error messages. |
| I/O Streams | Ways to give programme and recive informnation from programme |
| SHell | Command line interface used to interact with operating system |
| echo | It is used to print text in linux shell |
| Environment Variables | Variables used inside the sheel environment are called environment variables |
| Command Line Arguments | These are parameters that are passed to a program when it started |
| Where Command line arguments stored | The list of arguments are stored in sys module |
| Exit status | The value returned by a program to the shell |
| wc command linux | It prints value of lines,word and characters for our pyhton script |
| Finish successfully code | echo $? |
| Unicode standard used to convert an array of bytes into a string | UTF-8 |
| copy | Awesome! Calling this method of the os.environ dictionary will copy the current environment variables to store and prepare a new environment. |
| Log Files | |
| None | In python variable with no value is none and its not the samething like 0 , its just that it has no value |
| Objects in Python | Objects are way of organizing code in python and break things down to make it easier to think about complex ideas |
| Why use classes and objects | |
| Edge Cases | Inputs to our code that produce unexpected results and are found at the extreme ends of ranges of input we imagine our programms will typically work with |
| Casting | Using casting we can change types by using key words , int,str,float but you cant reverse cast values . However it can be done when written inside quotes |
| immutable type | String is immutable type,you cannot change string content after creation |
| String Concatenation | Plus operator concatenates two strings |
| Extend List | existing list.extend(newlist or element ) will extend the existing list |
| Sort List | .sort() only works on integers or strings seperately but cannot sort them when the list contains combination of numbers and strings |
| Tuples | A tuple is similar to list but you create them with paranthesis instead of square brackets. A tuple is immutable while the list is mutable |
| Dictionaries | Dictionaries are usefull when we have to give structure to data , like name, favorite sports and place of living.These types are keys and can be used to change values |
| Show Keys of Dictionaires | Mydict.keys() will show all the keys in the dictionary |
| Difference between compiler and interpreter | Compilers take the entire source code and produce object code/executable code while the interpreter execute the code line by line. |
| iteration on file object | We can iterate over file object using open but cannot strip it for that we have to use strip.lines() which gives a list in return |