Download presentation
Presentation is loading. Please wait.
1
Introduction to Python
Usman Roshan
2
Python Interpreter language: the Python interpreter executes each statement one at a time. No compilation or linking is required. Python programs are called scripts which are simple text files. To execute a script we pass it through the interpreter.
3
Data types Basic data types Collections Integer Float String
Boolean (true or false) Collections Lists Dictionaries (hash tables) Sets And more…
4
Expressions Numeric operators such as +, -, *, /, **
Logical operators such as and and or String operators such as in, +, [], [:] String and numeric functions such as len, abs, max, and min.
5
Assignment name = value Examples: sequence = “ACCCATA” x = 5 y = x + 2
6
Lists Ordered collection of basic types Examples: Operations on lists
Concatenate: list3 = list1 + list2 Access nth element: list1[n]
7
Dictionaries Dictionaries are like arrays, except that they are indexed by user defined keys instead of non-negative integers. Example h={‘A’:’T’, ‘C’:’G’} Operations on dictionaries Lookup: h[key]
8
Input and Output Input and output to files is done by creating a file object open(path, mode) Example: f = open(“myfile.txt”,”r”) f.readline()
9
Control structures Conditional statements if expression : statements1
else: statements2 Example max = 0 if(x > y): max = x max = y
10
Iteration for count in range(start,stop,step): for item in collection:
statements for item in collection: do something with item
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.