Python is an object-oriented programming language created by Guido Rossum in 1989. It is ideally designed for rapid prototyping of complex applications. It has interfaces to many OS system calls and libraries and is extensible to C or C++. Many large companies use the Python programming language, including NASA, Google, YouTube, BitTorrent, etc.
Water Industry Process Automation & Control Monthly - April 2024
Python Course Basic
1. Welcometo Python Course Basic
Naiyan Noor
BSc inCSE
BangladeshArmyUniversityofScienceandTechnology-BAUST
2. A snake.
A British comedy group called MontyPython.
A programming languge. Thedefinition of the language:words, punctuation (operators)
and grammar(syntax).
Thecompiler/interpreterof the Pythonprogramminglanguage. (aka. CPython).
What is Python?
3. Aneditor wherewe canwrite ina language.
A compiler or interpreterthat can translate our text to the language of the
computer.
What is needed to write a program?
4. Python2.x -old, legacy code at companies, answers onthe Internet. Retires on
January1,2020.
Python3.x -the one that youshould use. (not fully backward compatible)
Available since December 3, 2008.
Python 2 vs. Python 3.
7. Basically youcan use anytext editor to write Pythoncode. TheminimumI
recommendis to haveproper syntax highlighting. IDEs will also provide
intellisense, that is, inmost of the cases they will be able to understand what
kindof objects do youhavein yourcode and will beable to show youthe
available methods and theirparameters. Even better, theyprovide powerful
debuggers.
Editors, IDEs
9. PyCharmcommunity edition
Visual Codeof Microsoft
Spyder, a scientific environment (included in Anaconda)
Jupyter with IPython behind the scene.
IDLE(comes with Python)
KomodoofActiveState
Aptana
Pyscripter
PyDev(for Eclipse)
Wing IDE
IDEs
10. More or less theonly thing I do on thecommand line with pythonis to checkthe
version number:
Python on the command line
1 python -V
2 python --version
11. Youcan runsome Pythoncode without creating a file, but I don’t rememeber
ever needing this. If you insists
Python on the command line
1python-c "print 42"
1 python3 -c"print(42)"
Typethe following to get thedetails:
1man python
cmdline
12. Createa file called hello.py with the above content.
Open yourterminal or the Anaconda Prompt on MS Windows inthe directory
(folder)
Changeto thedirectory whereyousaved the file.
Runit by typing python hello.py or python3hello.py
Theextension is .py-mostly for the editor (but also for modules).
Parentheses after print() are required in Python3, but usethem evenif youare
stuck onPython 2.
First script - hello world
13. 1print("hello")
2
3 # Comments for other developers
4
5print("world") # morecomments
6
7 # print("Thisis not printed")
Comments
14. 1 greeting = "Hello World!"
2 print(greeting)”
Variables
Exercise: Hello world)
Tryyourenvironment:
Makesure you haveaccess to the right version of Python.
Install Pythonif needed.
15. What is programming?
Use some language totell the computer what todo.
Like a cooking recepie it has step-by-stepinstructions.
Taking acomplex problemand dividing it into small steps acomputer can
do.
16. What are the programming languages
A computer CPUis createdfrom transistors, 1and 0 values. (aka. bits)
Its language consists of numbers. (e.g 37 means move the content of ax
register to bxregister)
English? too complex, toomuch ambiguity.
Programming languages are in-beteen.
18. Words and punctuation matter!
What did you chose? (Correctly:choose, but people will usually
understand.)
Lets do the homework. (Correctly:Let’s, but most people will understand.)
Let’s eat, grandpa!
Let’s eat grandpa!
19. Words and punctuation matter!
Whatdid you chose? (Correctly:choose, butpeoplewill usuallyunderstand.)
Letsdo thehomework.(Correctly:Let’s,butmostpeoplewill understand.)
Let’seat,grandpa!
Let’seatgrandpa!
Programminglanguageshavea lotlesswords,buttheyarevery stricton thegrammar(syntax).
Amising comma can breakyour code.
Amissing space willchange themeaningof your code.
Anincorreectwordcan ruinyour day.
23. Add numbers & Add strings
“1a = 19
2 b = 23
3 c = a + b
4 print(c) # 42”
1 a = "19"
2 b = "23"
3 c = a + b
4 print(c) # 1923
Numbers Strings
Exercise: Calculations
“Extend the rectangular_basic.py from above to print both the area and the
circumferenceof the rectangle.
Write a script that has a variable holding the radius of a circleand prints out the area
of the circleand the circumferenceof the circle.
Write a script that has two numbers a and b and prints out the results of a+b, a-b,
a*b, a/b”