Week - 1 - Introduction - To - Python (1) - 085418
Week - 1 - Introduction - To - Python (1) - 085418
OOP Concept
❑ Object-oriented programming (OOP) is a method of structuring a
program by bundling related properties and behaviors into individual
objects.
❑ Conceptually, objects are like the components of a system.
❑ An object could represent a person with properties like a name, age,
and address and behaviors such as walking, talking, breathing, and
running.
Python
❑ Python is a general-purpose interpreted, interactive, language. It was
created by Guido van Rossum during 1985- object-oriented, and high-level
programming 1990. Like Perl, Python source code is also available under
the GNU General Public License (GPL).
• Programmers have some tools that allow them to build new tools
• When you make a mistake, the computer does not think you are “cute”. It
says “syntax error” - given that it knows the language and you are just
learning it. It seems like Python is cruel and unfeeling.
• You must remember that you are intelligent and can learn. The computer is
simple and very fast, but cannot learn. So it is easier for you to learn Python
than for the computer to learn English...
Talking to Python
Elements of Python
• Vocabulary / Words - Variables and Reserved words (Chapter 2)
• Sentence structure - valid syntax patterns (Chapters 3-5)
• Story structure - constructing a program for a purpose
Reserved Words
You cannot use reserved words as variable names / identifiers
x = 2 Assignment statement
x = x + 2 Assignment with expression
print(x) Print statement
• Most programs are much longer, so we type them into a file and tell
Python to run the commands in the file.
print('Smaller') Program:
No Output:
x = 5
Yes if x < 10: Smaller
x > 20 ? print('Smaller') Finis
if x > 20:
print('Bigger') print('Bigger')
No
print('Finis')
print('Finis')
n=5 Repeated Steps
No Yes Output:
n>0? Program:
5
print(n) n = 5 4
while n > 0 :
print(n)
3
n = n -1 n = n – 1 2
print('Blastoff!') 1
Blastoff!
Loops (repeated steps) have iteration variables that
print('Blastoff')
change each time through a loop.
It is used for:
•web development (server-side),
•software development,
•mathematics,
•system scripting.
Why Python?
•Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, (etc.)
•Python has a simple syntax similar to the English language.
•Python has syntax that allows developers to write programs with fewer lines than
some other programming languages.
•Python runs on an interpreter system, meaning that code can be executed as soon
as it is written. This means that prototyping can be very quick.
•Python can be treated in a procedural way, an object-orientated way or a
functional way.
Python Syntax
Example
x = 40 # x is of type int
x = 50
x = ”shifat” # x is now of type str
y = “Bangladesh"
print(x)
print(x)
Print(type(x))
print(y)
Built-in Data Types
In [3]: print('Welcome\nto\n\nPython!')
Welcome
To
Python!
Other Escape Sequences
Values such as 7 (an integer), 4.1 (a floating-point number) and 'dog' are all objects. Every object has a type and a
value. An object’s value is the data stored in the object. The snippets above show objects of Python built-in types int
(for integers), float (for floating-point numbers) and str (for strings).
Dynamic Typing
• Python uses dynamic typing—it determines the type of the object a variable refers to while executing your
code. We can show this by rebinding the variable x to different objects and checking their types:
• In [9]: type(x)
• Out[9]: int
• In [10]: x = 4.1
• In [11]: type(x)
• Out[11]: float
• In [12]: x = 'dog'
• In [13]: type(x)
• Out[13]: str
Getting Your Questions Answered
Online forums enable you to interact with other Python programmers and get your Python questions
answered. Popular Python and general programming forums include:
• python-forum.io
• StackOverflow.com
• https://www.dreamincode.net/forums/forum/29-python/
Thank You