Two Coursera classes (An Introduction to Interactive Programming in Python, Learn to Program: The Fundamentals) provide very good python beginner learning materials. Python is a Interpreted Language
Quick Summary and Python Notes
Example1 - Arithmetic Expressions
Example 2 - Working with Functions
Built In functions - max, abs
- Guido van Rossum is author of python, Good Wikipedia read about him in link
- Python Practice Book
- Notes from Advaced Python Workshop
- Online Editor available at CodeSkulptor
- Also check Very Good Question Is Python Interpreted or Compiled?
- Good Book to Get Started - A Byte of Python -Swarooph
- Learning Python the hard way
Basic Examples and beginner notes posted based on course notes. All Code can be tried in CodeSkulptor. There are a few syntax differences but this is similar to C programming language.
Example1 - Arithmetic Expressions
- Basic Arithmetic Expressions
- Variables, Assignments, Sample Exercise in link
Built In functions - max, abs
Example 3 - Custom Functions
- Example function to sum up two numbers
Example 4 - If Statement - Conditons , Else If and Else Operator
Example 5 - For Loop - Iteration
Example 6 - While Loop iteration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#https://github.com/swaroopch/byte-of-python/blob/master/programs/ds_using_dict.py | |
#using dictionary | |
ab = { | |
'Swaroop':'swaroop@swaroop.ch', | |
'Larry':'larry@wall.org', | |
'Matsumoto':'mat@ruby.org', | |
'Spammer':'spammer@hotmail.com' | |
} | |
print('Swaroop address is', ab['Swaroop']) | |
#Iterate | |
for name, address in ab.items(): | |
print('Contact {} at {}'.format(name,address)) | |
#Add Value | |
ab['Siva'] = 'sivaram2k10@gmail.com' | |
for name, address in ab.items(): | |
print('Contact {} at {}'.format(name,address)) | |
#https://github.com/swaroopch/byte-of-python/blob/master/programs/while.py | |
#https://github.com/swaroopch/byte-of-python/blob/master/programs/io_pickle.py | |
#https://github.com/swaroopch/byte-of-python/blob/master/programs/more_lambda.py | |
#https://github.com/swaroopch/byte-of-python/blob/master/programs/oop_subclass.py | |
#https://github.com/swaroopch/byte-of-python/blob/master/programs/exceptions_finally.py | |
#https://github.com/swaroopch/byte-of-python/blob/master/programs/ds_using_tuple.py | |
number = 23 | |
running = True | |
while running: | |
guess = int(input('Enter an integer:')) | |
if guess == number: | |
print('You guessed it') | |
running = False | |
elif guess < number: | |
print('Number low') | |
else: | |
print('Number High') | |
else: | |
print('While Loop Over') | |
print('Done') | |
#https://github.com/swaroopch/byte-of-python/blob/master/programs/ds_using_list.py | |
shoplist = ['apple','mango','carrot','banana'] | |
print('I have',len(shoplist),'items to purchase') | |
print('These items are:', end=' ') | |
for item in shoplist: | |
print(item,end=' ') | |
#append an item | |
shoplist.append('rice') | |
print('New Shopping List',shoplist) | |
print('Sorted Shopping List') | |
shoplist.sort() | |
print(shoplist) | |
print('First Item',shoplist[0]) | |
del shoplist[0] | |
print('First Item',shoplist[0]) | |
print(shoplist) | |
#https://github.com/swaroopch/byte-of-python/blob/master/programs/stdlib_logging.py | |
import os | |
import platform | |
import logging | |
if platform.platform().startswith('Windows'): | |
logging_file = os.path.join(os.getenv('HOMEDRIVE'), os.getenv('HOMEPATH'),'test.log') | |
else: | |
logging_file = os.path.join(os.getenv('HOME'),'test.log') | |
print(logging_file) | |
logging.basicConfig( | |
level=logging.DEBUG, | |
format = '%(asctime)s : %(levelname)s : %(message)s', | |
filename = logging_file, | |
filemode='w' | |
) | |
logging.debug('Start of program') | |
logging.info('Do Something') | |
logging.warning('Dying now') | |
Happy Learning!!!
No comments:
Post a Comment