Friday, March 19, 2021

Python 3


Python standards PEP8 https://www.python.org/dev/peps/pep-0008/#introduction
Private/Public/Protected --> http://radek.io/2011/07/21/private-protected-and-public-in-python/
Python documentation : https://docs.python.org/3/library/index.html
Python Thirdparty Packages  : https://pypi.python.org/pypi

Python course online for 3
https://www.python-course.eu/python3_course.php

Each file which we save is treated as module. The module name will be the name of the file which we have saved and if we have classes defined in the file/module the we need to be using following when we need to use the class in other module

from <<module/filename>> import <<classname>>

https://stackoverflow.com/questions/14583761/typeerror-module-init-takes-at-most-2-arguments-3-given

how to generate pyc file

https://stackoverflow.com/questions/5607283/how-can-i-manually-generate-a-pyc-file-from-a-py-file

Multi threading in Python

http://www.techbeamers.com/python-multithreading-concepts/
https://www.ploggingdev.com/2017/01/multiprocessing-and-multithreading-in-python-3/
https://www.python-course.eu/threads.php
https://pymotw.com/2/threading/
https://pymotw.com/3/threading/
http://www.pythoncraft.com/OSCON2001/

Logging in Python
http://www.patricksoftwareblog.com/python-logging-tutorial/
https://www.digitalocean.com/community/tutorials/how-to-use-logging-in-python-3
https://fangpenlin.com/posts/2012/08/26/good-logging-practice-in-python/


Everything in Python 3 is an object (Variable, Fucntion, even code)
Indentation is important in Python. Four spaces are common for indentation.
Comments are given like below
# --> To single line comment
'''

Python is dynamically typed language like JavaScript and groovy . Java is staticly typed language as we cannot change the variable type after we declared it.

Python is case-sensitive language like java so need to be careful about the variable names

Variable type can be fund using the function type()

type(<<variable name>>)
fname = 'pavan'
type(fname)

variable names in python prefer
a.  to have all lowercase
b. it cannot start with number or symbol
c. when we have two words then have _ between the words and have all small letters for the two names


Assignment in Python

a= 1
a= "apple"
a,b = 1, "apple"
a,b= b,a

Tuple  it is not allowed to modified
a =(1,2,3,4,5)


a= 1
id(a) --> returns address of a 
type(a)  --> returns class of a --> here it will give init

Mutable Objects can change value (Lists, Dictionaries, other object depending upon implementation)
Immutable Object cannot change value. (Numbers, String tuples)

Conditional code in Python

if condition :
   code
else:
  condition

Ternary Operator in other language is like below 

print(a<b : "foo" : bar")

but in python the ternary operator we have this as below 

print("foo" if a<b else "bar")

while Loop

while condition:
     code

Eg:

a,b = 0,1
while b < 50:
   print(b)
   a,b= b, a+b
print("Done");

For Loop

for a in (1,2,3,4,5):
 print(a)


For loop also we can write else

for a in range (1,20):
    print(a);
else :
    print("I am done");



function in python

def function(parameters) :
  code


Eg:
  def fullname(fname, lname) :
     print ("Full name is {} {}".format(fname,lname));

fullname("pavan","tummala")
    

yield --> is used for generator in python

Exception handling

try:
  code
except:
  code

like

try:
  code
except IOError as e:
  print(e)
  code

Python does not support method overloading is same method is defined more than once with different arguments the last method will be visible . It is something similar to javascript.
refer below link
https://stackoverflow.com/questions/34248842/how-are-python-inheritance-rules-different-with-that-of-java
http://www.informit.com/articles/article.aspx?p=2145970


---------------------------------------------------------------------------------------

To install PIP on suse linux 
Step 1 : Download pip from internet 
    Download the file from internet (It will download the latest version wihich is 3)\

         curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

        If we want for specific version then download the specific version 

                curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py
Step 2 : Execute the below command 
     Then give the below command 
          python get-pip.py


No comments:

Post a Comment