| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Open window.powershell
Python is programing language which help us to communicate with computer or laptop even with any type of opreating system. It is very simple and easy to understand like reading a simple "English". Python pseudo code nature make python easy to learn for non-codder to just start learning coding and machine learning
Pip is the package maneger for pyhton like Node or npm in package manager for javascript/Node.js.you can use pip to install packages or a module on your system.
Module is a file with code written by somebody else which you can import byt installing that module in you program using pip
*** Built-in => which you during installation of python in your system.*** *** External => which you have to install using "pip" in your system.***
Simple example of Python working that is you can use pyhton as "Calculater" REPl - Read Evaluate Print loop
Basiclly developer use this for give instruction in code base. Comments will never show on Browser when we run file on web-browser. Comment can be single line or Multiple line
for Javascript we use console.log("Hello World") ==> print("Hello World") for Python Language
Variable is name given to value for storing in your program or with Declare a varible name with value you can use that anywher in that particuler file TO declare a variable name you have to follow set of Rules:
Datatype in python- mostly used datatype are as following:- Integerns Floating point numbers Strings Boolean None
1. Arithmetic operators => "+,-,/,*" common examples. 2. Assignment operators => "=,+=,-=" you will use in further steps. 3. Comperison operators => "==,>,>=,<,<=,!=" for compare value and type also. 4. Logical operators => "and,or,not" check logic in functions.
String is just a Datatype in Python You can write with three ways
what you need to know for use slicing?
Can you use Negtive index number in Python?
Can you skip the index number in Python?
-- List are basically set of values of any type. Any type menas it can be Strings, Boolean, Integers, Floating points etc.
Booleans list - [true,false,true]
Integers list - [1,2,3,45,6,8]
Strings list - ["Phython","Java","C#","Javascript"]
Floating points list - [0.35,1.52,35.89,1.105]
List Indexing -- Index is always same in every case: - it will start from number "0". - It will stop at length-1 index number.
Can change value of list -- Answer is Yes! - a=[1,2,4,3] --> for change value you index of that place where you want to change - a[2]=3 --> now "4" will change with "3" - a[3]=4 --> now "3" will change with "4"
Can string Functions can implemen in Lists? -- Answer is Yes! but not all of them - Len() to find length of list. - Slicing also can be implement in list like "[0:4]"
For more understand through examples check file "ListMethods.py" -- .Sort(): for sorting of list in assending order. -- .reverse(): for sorting of list in desending order. -- .append(): for add someting in the end of list. -- .insert(): for add something on selected index value. -- .pop(): to delete value from list by index number or if not give any index number then last item will be deleted. -- .remove() to remove item by Value providing it. for more methods
Immutable in nature->menas you can't make changes in it -- Tuples are used to store multiple items in a single variable. Tuple is one of 4 built-in data types in Python used to store collections of data, the other 3 are List, Set, and Dictionary, all with different qualities and usage. A tuple is a collection which is ordered and unchangeable. - Tuple types:
-- No,you got an error because you read values from tuple but cannot chnage that value.
for more see practical check file "Tuples.py" code
-- To count how many time same word in tuple comes. syntax for this function count() - print(tuple.name(value_for_check)) -- To first occurence of value in tuple. syntax for this function count() - print(tuple.index(value_for_check))
Link for Tupple More Information
Dictionary mean not Oxford dictionary
-- In simple mean you work with Javascript than you Know about "Objects". Object have "Key-value" pairs. Same in Python this known as "Dictionary".
syntax
- For update new key-value pair in dictionary
newItem={
"Mac-Book":"New_wish"
}
*Dictionary.name(newitem)*
*print(Dictionary.name(name_of_item))*
- For get value of key you can use ".get()"
*print(Dicationary.name.get("key_name"))*
but you may confuse here that you can value by simply write
*print(Dictionary.name["key_name"])* then what is nee of ".get()" ?
simple reason behind this if you don't have that "value" then ".get()" will show "NONE" where simple "["key_name"] will through error because in simple ["key_value"] you have take care that key-name should be there which you written there.
<a href="https://docs.python.org/3/tutorial/datastructures.html#dictionaries">More Dictionary Methods</a>
Set is a Collection of non-repetitve elements
-- Conditional experssions means when have some situation or condition to full fill "If" or "else" best example of this is you can read below: when are in school in 10th standard you for "Iphone" to your "Dad" and he say if you "marks" is greater then 90% than you will get it or if you score are above 80% than you will get "Samsung". If your marks above 70% than "realme" or if you get below than 60% than "Chappal" this is called Conditional Expression
Syntax
what is your reaction when i tell you that it can be done in two lines of code!!!
-- Yes Loops gonna help us in this work --
- Syntax of while loop is show below:
While condition : #loop will until it == true#
#here we right body code of loop
- Syntax of while loop is show below:
for ("name of initial value") in varibale or etc.
for "total" in "table" :
print(total)
- this will help to now that our condition change to False. "you can asume this" example in "RangeFunction.py" file.
- Break is used to stop the loop on certain point or conditon. when that point is valid or condition gonna true loop will stop automaticaly. Let understand with example in file name "RangeFunctions.py".
- Continue will use to skip something from intration on problem .More easy way "jab hume kisi ko ignore krna ho to bus uski baat unsunna krdo." Same we are doing this here Let understand with example in file name "RangeFunctions.py".
- We mostly use "Pass" on there where if condition is pass but nothing to do with that in those cases you can use Pass. *Example hume logo ko jab koi kam nai krne mood nai hota to hum kisi ki baat ka koi rply nai dete* I know you need example on this and i know you where you have to check.
- A function is set of statement to do specific task
for large scale working where can't track of working of program on that place functions played very good role. Functions are reuseable in nature
Basically two types of function are in pyhton:
Built in function you get this when you install pyhton in you system
User defined function which you make according to your work
Example of In-Built functions
Example of In-Built functions find pecent of students scores:
def percent(score): return (sum(score)/600*100) percent=percent(score)result with this function. print(percent)
Function Arguments: you can pass value in function as "argument" and function will return a value to print in your terminal as shown in upper example.
Default argument: this will help you in two ways:
Example
name=input("Enter Name \n")
def sayHi(name="Viewers):
print("Hello good morning " + name)
sayHi(name)```
Let understand will factorial Example
fact=5 factorial=1 for i in range(fact): factorial=factorial*(i+1) print(factorial)
Now same work with Functions
n=int(input('Enter number \n'))
def Factorial(n):
start=1
for i in range(n):
start=start*(i+1)
return start
print(f"Factorial of {n} in {Factorial(n)}")
print(Factorial(n))
Recursive manner with Function but you hav to give base case when function comes to base-case than it will stop and return a value for that case Example
def Recursive_Factorial(n):
if n==1 or n==0:
return 1
return n*Recursive_Factorial(n-1)
print(f"Factorial of {n} in {Recursive_Factorial(n)} ")
Strip() function used for remove space from start and at end of value
randon.randint(start_range, end_range)
Now with Book Defination "Using input() and print() Function. A good program should effectively communicate any input in Python from the user and display a result to the outside world. A user can give a program input manually from a keyboard or use data from an external source, such as a file or a database."
Typee of Files
Python has lot of functions for reading, writing, updating and deleting files.
Opening a File
open("file_name","command")
command can be - read, write, update and delete
data=open("file_name","r")
info=data.read()
print(info)
data.close()
data=open("file_name")
info=data.read()
print(info)
data.close()
data=open("file_name")
info=data.read(5)
print(info)
data.close()
file=open("myInfo.txt")
letRead=file.readline()
print(letRead)
file.close()
letFile= open("mydata.txt",'w')
Details= letFile.write("Make this file with name mydata")
letFile.close()
letFile= open("mydata.txt",'a')
Details= letFile.write("Make this file with name mydata")
letFile.close()
You can both thing read and write with this syntax 1. to read file with this syntax: with open('mydata.txt','r') as f: a=f.read() print(a) 2. to write file with this syntax: with open('mydata.txt','a') as f: a=f.write() print(a)
solving s problem using object or creating a object is called object oriented programing.for reusing of code is more focuesd in this concept. that is called "DRY principle".DRY --> Don't repeat yourself.
- Class is nothing judt blueprint of objects.
they never take memory untill you don't usethis
Class Students:
#methods & variables
- object is an instantation of class. after object instatation memory will be allocated to class.where user don't need to borther that how this will work.
class Employee:
company="Google" --> [specific to each class]
varinder=Employee() --> [Object instantiation]
varinder.campany
Employee.company="Youtube" ->[Changin class attribute]
An attribute that belongs to the instance (object).More simplyfiy this than you can say uniques things for different object: Example from previous class:
varinder.name="Varinder Brar" varinder.salary="75k" --> [Adding instance attribute]
Note: Instance attributes take preference over class attributes during assognment & retrival it will check varinder is present in object?
self refers to the instance of the class. It is automatically passed with a function call from an object
```
varinder.getSalary() --> here self varidner
|_______ equiratent to employee.getSalary(varinder)
```
*this function get salary is defined as:*
```
class Employee:
company="Google"
def getSalary(self):
print("salary is not there)
```
# Statix methods
like if you need a function where you don't want use self parameter on that place you can use static method.
```
@staticmethod --->decorater to mark greet as a static method
def greet():
print("Hello Bhai")
```
# "__init__()" Constructor
this is a special method which is first run as soon as the object is created. this also known as constructor.
*It takes self argument and can also take futher arguments*
```
class Data:
info="names"
def __init__(self,name,company,role,valueofcampany):
self.name=name
self.company=company
self.role=role
self.valueofcompany=valueofcampany
print("Name list is ready")
def details(self):
print(f"The name is {self.name}")
print(f"The company name is {self.company}")
print(f"Role in campany as a {self.role}")
print(f"The value of campany is {self.valueofcompany}")
Brar=Data("Varinder Brar","Youngstr","Owner",1000)
```
- In Simple words you can say that class we make first or parent class of children classses. ***Syntax***
class Emplyoee:
company="JavascriptFolks"
def showDetails(self):
print("Emplyoee Data")
- this class have attributes or parts are you take from parent class mean Base class and other custom things you can addon accordinh to your need.
***Syntax***
```
class Programers(Emplyoee):
language="Python"
def getlanguage(self):
print(f"this language is {self.language}")
```
You can over-riding drive class
**Single Inheritance**: - Single inheritance called in that situation when child or drive class inherite only from single parent or base class. **Multiple Inheritance** - Multiple inheritance occurs when the child or drive class inheritnace from more than one parent or base class. **Multilevel Inheritance** - When a child or drive class become a perent for another child or base class. ***Incase attribute is present in child class than it will take from nearest parent class***
class IphonePrice:
company="Apple"
price="150k"
location="Calefornia"
@classmethod
def reducePrice(self,newprice):
self.price=new
main=IphonePrice()
print(main.price)
main.reducePrice("80k")
print(main.price)
print(IphonePrice.price)
class Employee:
@property
def name(self):
return self.Name
data=Employee()
Name="varinder"
print(data.name)
@name.setter
def name(self,value):
self.name=value
| Back | FazBrowse Home | New Git URL |