Professional Documents
Culture Documents
Python Overview
Python is a great and friendly language to use & learn, can be adapted to
small & big projects.
Open source.
Can use both procedure oriented and OOPS concepts
Dynamic typed language- don’t have to explicitly declare variable
Python is formally an Interpreted language.
Easy to interface with Java / C / ObjC
Built-in-data structures – Lists, tuples, dicts
Python Installation
Windows
Visit https://www.python.org/downloads/ and download
the latest version.
Set path
Python interpreter or idle
Linux
Already installed
Python (alt+f2)
Python Interactive Shell
% python
Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
Comments
Starts with #
Variables
Binding between a name and an object
Single variable assignment: x = 1
Multi variable assignment: x, y = 1, 2
Swap values: x, y = y, x
Variables are examples of identifiers
First char must be alphabet or _, followed by
digit/alphabet/_
Input & Output
Input(“enter a number “)
raw_input – takes input in string form
Output:
Print(“name”)
Print ‘{0} age is {1}’,format(name,age)
Print “name”
print "Name:", name, "\nAge:", age
Escape Sequences
\\ - backslash- print ‘\\’ -- \
\’ - prints single quote –
\’’ – double quote
\n – new lone
Data Types
>>> “chen".upper()
‘CHEN'
Operators And Expressions
Logical Operator Bitwise Operator
not unary negation ∼ bitwise complement (prefix unary operator)
and conditional_and & bitwise and
or conditional_or | bitwise or
ˆ bitwise exclusive-or
<< shift bits left, filling in with zeros
Equality Operator >> shift bits right, filling in with sign bit
is same identity
is not different identity
== equivalent Sequence Operator
!= not equivalent s[j] element at index j
s[start:stop] slice including indices
[start,stop)
Comparison Operator s + t concatenation of sequences
< less than k * s shorthand for s + s +... (k
< = less than or equal to times)
> greater than val in s containment check
> = greater than or equal to val not in s non-containment check
Arithmetic Operator
+ addition
− subtraction
* multiplication
/ true division
// integer division
% modulo operator