@vinaymavi

Agenda

  • What is python
  • How to install
  • Editors to work
  • Python 2.7 vs 3.x
  • REPL introduction 
  • Hello World
  • Data Types
  • Conditional Statements

What is python

Python is an interpreted high-level programming language for general-purpose programming. Created by Guido van Rossum and first released in 1991, Python has a design philosophy that emphasizes code readability, notably using significant whitespace. It provides constructs that enable clear programming on both small and large scales.

Python features a dynamic type system and automatic memory management. It supports multiple programming paradigms, including object-oriented, imperative, functional and procedural, and has a large and comprehensive standard library.

How to install

https://www.python.org/downloads/

How to install

Local Modules

Editors

Local Modules

Python 2.x

Python 3.x

print, print() print()
str, unicode str by default has unicode support
Integer devision
3/2 = 1
3/2.0 = 1.5
Integer devision
3/2 = 1.5
 

REPL

REPL - Read-eval-print Loop

hello world

# Python 2.x

print "Hello World"

print("Hello World")


#Python 3.x

print("Hello World")

Data Types

  • Number
  • String
  • Tuple
  • List
  • Dictionary

Data Types

Number

a = 10 
b = 10.0
c = 9
# Math operations 

a/b = 1
c/a = 0
c/b = 0.9

Data Types

String

msg1 =  'Hello World'
msg2 = "Hello World"
msg3 = """Hello World"""


# Print
print msg1
print msg2
print msg2

# Formatting 

print "Hell0 %s"% 'world'
print "Hello {}".format('world')
print "Hello {0} {1}".format('vinay','kumar')

# Substring 
# strip,lstrip,rstrip 

# dir 

# help

Data Types

Tuple

t =  (1,2,3,4)


print t

Data Types

List

l =  [1,"tow",3.0,('one','tow','tree')]


print t

# Operation
append

# Get values 

Data Types

Dictionary

d =  {
'msg':"Hello World",
'number':10
}


# access 

#d['<key_name>']
print d['msg']
print d['number']

What is boolean

Mutable and Immutable

Hash bang

#!/usr/bin/env python 
print "Hello World"

Make file executable.

Read values

#!/usr/bin/env python 

# Python2

msg  = raw_input("Enter your input")

print msg

# Python3

msg  = input("Enter your input")

print msg

Keywords

Conditional Statements

x = 10
if x == 0:
    print "X is zero"
elif x == 10:
    print "X is equal to 10"
else:
    print "X = %d"% x

Conditional Statements


# if as expression.

"True" if 1 else "False"

"True" if 0 else "False"

Q &A

Python1

By Vinay Mavi

Python1

Python basic and installation

  • 293