This document provides an introduction to the Python programming language. It discusses what Python is, who created it, why it is popular, and how to get started. It also covers Python data types, operators, input/output, lists, tuples, sets, dictionaries, decision making, loops, and functions. The document encourages practicing, getting a mentor, and having impactful past work to help get into product companies like Amazon. It promotes the codingpros.in website for learning Python.
3. What is Python?
Python is an interpreted, object-oriented,
high-level programming language with
dynamic semantics.
Python/Inventor
Guido van Rossum
It was created by Guido van Rossum, and
first released on February 20, 1991.
Interpreted
Object Oriented
High-level
Dynamic semantics.
More info: https://www.python.org/doc/essays/blurb/
4. Why Python?
Python’s popularity
Python is used in Data Science
Python’s scripting & automation
Python is used with Big Data
Python supports Testing
Computer Graphics in Python
Python used in Artificial Intelligence
Python in Web Development
Python is portable & extensible
Python is simple & easy to learn
Large Community support
13. https://stackoverflow.com/questions/2174124/why-do-we-ne
ed-tuples-in-python-or-any-immutable-data-type
So, why the ……. do we need
Tuples?
1. immutable objects can allow substantial optimization; this is
presumably why strings are also immutable in Java, developed
quite separately but about the same time as Python, and just about
everything is immutable in truly-functional languages.
2. in Python in particular, only immutables can be hashable (and,
therefore, members of sets, or keys in dictionaries). Again, this
afford optimization, but far more than just "substantial" (designing
decent hash tables storing completely mutable objects is a
nightmare -- either you take copies of everything as soon as you
hash it, or the nightmare of checking whether the object's hash has
changed since you last took a reference to it rears its ugly head).
14. Sets and Dictionaries
A Set is an unordered collection data type that is iterable, mutable and
has no duplicate elements. Python’s set class represents the
mathematical notion of a set. The major advantage of using a set, as
opposed to a list, is that it has a highly optimized method for checking
whether a specific element is contained in the set.
Dictionary in Python is an unordered collection of data values, used to store
data values like a map, which unlike other Data Types that hold only single
value as an element, Dictionary holds key:value pair. Key value is provided in
the dictionary to make it more optimized.
15. Using Sets
Set:
myset = set(["a", "b", "c"])
Also_a_set = {“a”, “b”, “c”}
# Adding element to the set
myset.add("d")
print(myset)
print(Also_a_set)
#Output:
{“d”, “c”, “a”, “b”}
{“a”, “b”, c”}
16. Using Dictionaries
Dictionary:
# Creating a Dictionary
# with Integer Keys
Dict = {1: 'Geeks', 2: 'For', 3: 'Geeks'}
print("nDictionary with the use of Integer Keys: ")
print(Dict)
# Creating a Dictionary
# with Mixed keys
Dict = {'Name': 'Geeks', 1: [1, 2, 3, 4]}
print("Dictionary with the use of Mixed Keys: ")
print(Dict)
17. How Do Dictionaries and Sets Work?
Dictionaries and sets use hash tables in order to achieve their O(1)
lookups and insertions. This efficiency is the result of a very clever
usage of a hash function to turn an arbitrary key (i.e., a string or
object) into an index for a list. The hash function and list can later
be used to determine where any particular piece of data is right
away, without a search. By turning the data’s key into something
that can be used like a list index, we can get the same
performance as with a list. In addition, instead of having to refer to
data by a numerical index, which itself implies some ordering to the
data, we can refer to it by this arbitrary key.
18. How Do Dictionaries and Sets Work?
hashcode = hash(key)
Index = hashcode%x
Index = hashcode&(n-1)
Index = func(hashcode)
Lookup time: O(1)
20. You can use a List to store the steps necessary to cook a chicken, because Lists
support sequential access and you can access the steps in order.
You can use a Tuple to store the latitude and longitude of your home, because a
tuple always has a predefined number of elements (in this specific example, two).
The same Tuple type can be used to store the coordinates of other locations.
You can use a Set to store passport numbers, because a Set enforces uniqueness
among its elements. Passport numbers are always unique and two people can't have
the same one.
You can use a dictionary to store roll numbers and name of students in a class.
(https://en.wikipedia.org/wiki/Map_(higher-order_function) )
Ok… but…. Where do we use all of it?
21. Decision Making in
Python
num = 3
if num >= 5:
print("Greater than 5")
elif (num<5 and num>0):
print(“+ve and Less than 5”)
else:
print("Negative number")
22. Loops (On and on we go)
count = 0
while (count < 3):
count = count + 1
print("Hello Geek")
n = 4
for i in range(0, n):
print(i)
25. Let’s use what we have just learnt to
build a calculator:
https://repl.it/languages/python3
26. How to get into product based
companies like Amazon?
Practice
Practice more
Get a mentor
Don’t be in doubts. Get it cleared!
Have past work that shows impact.
Let codingpros.in help you!