free workshop all over the India ➔ Past , present, future of Python • Numbers • Strings • List • Tuples • Dictionary • Control statements - if/for • functions • in built functions • classes
the month of August 2013, just before the annual PyCon India conference, a bunch of volunteers came together and decided to spread the love of Python far and wide. A lot of colleges and instructors came together conducting numerous workshops, and we celebrated that month as the PythonMonth. Python Month shows how people passionate about python language , the response and enthusiasm was tremendous. PSSI decides if people wanted to learn, and there were people ready to teach, why restrict ourselves to just one month from that day PythonExpress brings tutors, organizations and students together to spread the love of Python far and wide.
a programming language; in fact it was released by its designer, Guido Van Rossum, in February 1991 while working for CWI also known as Stichting Mathematisch Centrum. Many of Python’s features originated from an interpreted language called ABC. Rossum wanted to correct some of ABC’s problems and keep some of its features. At the time he was working on the Amoeba distributed operating system group and was looking for a scripting language with a syntax like ABC but with the access to the Amoeba system calls, so he decided to create a language that was generally extensible. Python past, present, and future with Guido van Rossum: https://talkpython.fm/episodes/show/100/python-past-present- and-future-with-guido-van-rossum
language for general- purpose programming. Python is one of the language requires less code to complete basic tasks, making it an economical language to learn. Python code is often 3-5 times shorter than Java, and 5-10 times shorter than C++ . Python is a general-purpose language, which means it can be used to build just about anything, which will be made easy with the right tools/libraries. Professionally, Python is great for backend web development, data analysis, artifcial intelligence, and scientifc computing. Many developers have also used Python to build productivity tools, games, and desktop apps, so there are plenty of resources to help you learn how to do those as well.
foating point numbers and complex numbers. They are defned as int, foat and complex class in Python. Integers and foating points are separated by the presence or absence of a decimal point. 5 is integer whereas 5.0 is a foating point number. Complex numbers are written in the form, x + yj, where x is the real part and y is the imaginary part. We can use the type() function to know which class a variable or a value belongs to and isinstance() function to check if it belongs to a particular class.
number into another. This is also known as coercion. We can also use built-in functions like int(), foat() and complex() to convert between types explicitly. For eg: >>> int(2.3) 2 >>> int(-2.8) -2 >>> foat(5) 5.0 >>> complex('3+5j') (3+5j) When converting from foat to integer, the number gets truncated (integer that is closer to zero).
module that comes with Python. While foating point numbers have precision up to 15 decimal places, the decimal module has user settable precision. For eg: >>> from decimal import Decimal >>> print(Decimal('1.1')+Decimal('2.2')) 3.3
we declare strings in between “” or ‘’ or ‘” ‘” or “”” “””. The examples below will help you to understand string in a better way. >>> s = "I am Indian" >>> s 'I am Indian' >>> s = 'I am Indian' >>> s 'I am Indian' >>> s = "Here is a line\ ... splitted in two lines" >>> s 'Here is a linesplitted in two lines'
have to use triple single/double quotes. >>> s = """This is a ... multiline string, so you can ... write many lines""" >>> print(s) This is a multiline string, so you can write many lines
methods available, we already saw some of them like s.split(” ”). >>> s = "Himanshu Awasthi" >>> s.title() 'Himanshu Awasthi' >>> z = s.upper() >>> z 'HIMANSHU AWASTHI' >>> z.lower() 'himanshu awasthi' >>> s.swapcase() 'hIMANSHU aWASTHI'
called list. Lists can be written as a list of comma-separated values (items) between square brackets. >>>list = [ 1, 342, 2233423, 'Kanpur', 'python'] >>>list [1, 342, 2233423, 'Kanpur', 'python'] Lets practice ^^
Comprehensions: For example if we want to make a list out of the square values of another list, then; >>>a = [1, 2, 3] >>>[x**2 for x in a] [1, 4, 9] >>>z = [x + 1 for x in [x**2 for x in a]] >>>z [2, 5, 10]
= 'this', 'is' , 'kanpur' , 'tech' , 'community' >>> tuple ('this', 'is', 'kanpur', 'tech', 'community') >>> for x in tuple: ... print(x, end=' ') ... this is kanpur tech community Note :Tuples are immutable, that means you can not del/add/edit any value inside the tuple
where keys are unique. We declare dictionaries using {} braces. We use dictionaries to store data for any particular key and then retrieve them. >>> data = { 'himanshu':'python' , 'hitanshu':'designer' , 'hardeep':'wordpress'} >>> data {'hardeep': 'wordpress', 'hitanshu': 'designer', 'himanshu': 'python'} >>> data['himanshu'] 'python' Lets practice Add/Del elements in dictionary
pair. >>> dict((('himanshu','python') , ('hardeep','wordpress'))) {'hardeep': 'wordpress', 'himanshu': 'python'} If you want to loop through a dict use Iteritems() method. In python3 we use only items() >>> data {'hardeep': 'wordpress', 'hitanshu': 'designer', 'himanshu': 'python'} >>> for x , y in data.items(): ... print("%s uses %s" % (x ,y)) ... hardeep uses wordpress hitanshu uses designer himanshu uses python
sequences same time, for that use zip() function. Eg: >>> name= ['ankit', 'hardeep'] >>> work= ['php' , 'wordpress'] >>> for x , y in zip(name , work): ... print("%s uses %s" % (x ,y)) ... ankit uses php hardeep uses wordpress
within a same program. Functions help us to do so. We write the things we have to do repeatedly in a function then call it where ever required. Defning a function: We use def keyword to defne a function. General syntax is like def functionname(params): statement1 Statement2 >>> def sum(a, b): ... return a + b
functionality together. We defne a class in the following way : class nameoftheclass(parent_class): statement1 statement2 statement3 >>> class MyClass(object): … a = 90 … b = 88 ... >>>p = MyClass() >>>p <__main__.MyClass instance at 0xb7c8aa6c> >>>dir(p)
Python classes, it is the constructor method for a class. In the following example you can see how to use it. class Student(object): def __init__(self, name, branch, year): self.name = name self.branch = branch self.year = year print("A student object is created.") def print_details(self): print("Name:", self.name) print("Branch:", self.branch) print("Year:", self.year)