-- Python is an interpreted, object-oriented, high level programming language with
dynamic semantics.
-- Python code can invoke C and C++ programs,can integrate with java and .net
components.
-- IDE - integrated development environment.
-- Python is case sensitive.
-- 7 types of operators in python. They are:
-- Arithmetic - +, -, *, /, %(remainder), **(power)
-- Assignment - =, +/ etc.
-- Comparison - >, <, ==, !=
-- Logical - and, or, not
-- Bitwise - a|b, a&b, a^b (all boolean values)
-- Identity - is , is not
-- Membership - in, not in(exclusively used in lists).
IDLE is an editor
-interactive shell & file editor
- procedure oriented.
- file editors = sublime and pycharm are code editors for python.
- raw_input = lets user type in value
- int(), str(), float() convert values data type
- boolean values = True, False
- the input ake from the 'raw_input' will be string type.
DataType
-- python is loosely typed language. Therefore, no need to define the datatypes of
variables.
-- datatypes 1) Immutable -- Numbers, Strings, Tuples
2) Mutables -- Lists, Dictionaries, Sets
-- A tuple is a sequence of immutable python objects like float, int, string etc.
tuples defined in circle brackets. Can't be modified.
-- A list is a sequence of mutable python objects like float, int, string etc.
lists defined in square brackets. Can be modified.
-- Dictionaries are most flexible built-in data type of python. In Dictionaries
items are stored and fetched by key, instead of by
positional offset.
-- print(string1+string2) - gives concatenation of the 2 strings.
-- print(string*3) - prints the string 3 times
-- print(string[3:6]) - prints the output by slicing the characters mentioned from
the string.
-- print (string[-2]) - prints last second character of the string.
-- Type specific methods for String variable are: 1) find() 2)replace() 3) split()
4) count() 5) upper() 6) max() 7) min() 8) isalpha().
-- Type specific methods for List variable is 1) [Link]('d') 2)
[Link](['c','d']) 3) [Link](2, 'b') 4) [Link]()
-- Dictionary methods are 1) myDict[1] 2) len(myDict) 3) [Link]() 4)
[Link]() 5) [Link]() 6) [Link](1)
7) [Link]({3:'c'}) 8) [Link](2)
flow control statements:
if, if..else, if..elif..else, for, while, break, continue
File Handling & I/O Methods
-- A file or a computer file is a chunk of logically related data or information
which can be used by computer programs.
-- open(filename, mode)
-- read()
-- write()
-- close()
1st
print ('Hello world!')
print ('what is your name')
name = raw_input()
print ('It is a nice name '+ name)
print ('length of the name is:')
print (len(name))
print ('what is your age?')
age = raw_input()
print ('you will be ' + str(int(age) + 1) + 'in one year')
2nd
name = 'arun'
age = 300
if name == 'Arun':
print('thanks for entering a name')
elif age < 12:
print('You are not omkar kiddo')
elif age > 200:
print('You are arun brother')
3rd
print('Enter a name')
name = raw_input()
if name != '':
print('thanks for entering a name')
else:
print('You did not enter a name')
4th
name = ''
while True:
print('please type your name.')
name = raw_input()
if name == 'Arun':
print(name)
break
print('Thank you!')
5th
print('My name is')
for i in range(5):
print('Jimmy Five times' + str(i))