Upload
wwwmyassignmenthelpnet
View
176
Download
0
Embed Size (px)
Citation preview
Python assignment help
www.myassignmenthelp.net
What is Python
• Multi-purpose i.e, Web, Graphical user interface
(GUI), Scripting and many others.
• Strongly typed as well as dynamically typed.
• Focus on readability as well as productivity.
• Object oriented.
• Interpreted.
www.myassignmenthelp.net
Characteristics
• Easy to Learn • High-level Language• Interactive shell• Strong introspection• Cross platform• Object Oriented• Everything is an object• Free and Open Source
www.myassignmenthelp.net
CONT..• Useful built-in types (lists, dictionaries)• Clean syntax, powerful extensions• Interpreted• Interactive• Commonly used for producing HTML content on
websites. Great for text files• Functional• Extensive Libraries
www.myassignmenthelp.net
Languages
www.myassignmenthelp.net
• Few important types:– FORTRAN• Technology
– COBOL• Business Information
– LISP• Logic as well as AI
– BASIC• Easy Language
The Python Interpreter
• Python can be an interpreted terminology
• The actual interpreter has an interactive environment in order to perform using the language
• Results
>>>> 4 + 59>>>> 4 < 15 True>>>> “print me”“print me”>>>> print “print me”print me>>> >
www.myassignmenthelp.net
Print “Hello World”
• Open a terminal window and type ‘python’• If on Windows open a Python IDE such as IDLE• At the prompt type “Hello World !!”
>>>> ‘Hello World !!'
‘Hello World !!'
www.myassignmenthelp.net
The print Statement
>>>> print “Welcome”Welcome>>>> print “Welcome”, “Ram”Welcome Ram
• Elements divided through commas , print with a space between them• The comma at the end from the statement (print “Welcome”,) won't printing the new line character
www.myassignmenthelp.net
The Documentation
>>> > “welcome'
‘welcome'
>>> #‘comment'
>>>
‘#’ : this symbol is used for starts a comment
www.myassignmenthelp.net
Variables• Do not need to declare• Should determine (initialize)
• Using uninitialized variable improves exception
• Certainly not typedin case ,friendly: greeting = “Hello World"else: greeting = 12**2print greeting
• Anything is often a ‘variable’:• Even characteristics, classes, modules
www.myassignmenthelp.net
Everything is an object
• Everything means, which includes functions as well as classes
• Data type is usually a property of the object instead of on the variable
>>>> x = 9>>> x9>>>> x = “Welcome”>>>> x“Welcome” >>>>
www.myassignmenthelp.net
Interactive “Shell”• This is good for learning the language• Good for experimenting for using your library• Good for testing for using your own modules• 2 variants: IDLE (GUI),
python (command line)• Kind statements or even expressions at prompt:
www.myassignmenthelp.net
>>>> print "Hello, World"Hello, World>>>> x = 12**2>>>> x/272>>>> # (this is a comment)
Numbers• The typical suspects:
• 13, 3.15, 0xFF, 0377, (-1+2)*3/4**5, abs(x), 0<x<=5• C-style shifting & masking:
• 1<<17, x&0xff, x|1, ~x, x^y• Integer division truncates:
• 1/2 -> 0 # 1./2. -> 0.5, float(1)/2 -> 0.5• fixed in the future
• Long complicated:• 2L**100 -> 1267650600228229401497607505376L–Within Python 2.2 as well as past, 2**100 will the
same
www.myassignmenthelp.net
Strings• ‘Hello’+ ‘World’ ‘HelloWorld’ # Concatenation• ‘Hello’*2 ‘HelloHello’ # Repetition• ‘Hello’[0] ‘h’ # Indexing• ‘Hello’[-1] ‘o’ # (From end)• ‘Hello’[1:4] ‘ell’ # Slicing• len(‘Hello’) 5 # Size• ‘Hello’< ‘jello’ 1 # Comparison• ‘e’ in ‘hello’ 1 # Search• ‘escapes: \n etc, \033 etc, \if etc’• 'single quotes' """triple quotes""" r ‘raw strings’
www.myassignmenthelp.net
Lists
• Variable arrays, definitely, not Lisp-like linked lists
• x = [99, [‘on’, ‘the’, ‘wall’]]
• Exact same providers for strings• x+y, x*3, x[0], x[-1], x[1:], len(x)
• Item and slice assignment• x[0] = 98
-> [98, [‘on’, ‘the’, ‘wall’]]• del x[-1] # -> [98]
www.myassignmenthelp.net
Tuples
• Tuples tend to be immutable versions associated with lists
• One strange may be the structure to create a tuple along with one element:‘,’ is required to differentiate from the numerical expression (2)
>>>> a = (1,2,3)>>> >a[1:](2, 3)>>>> b = (2,)>>> >b(2,)>>> >
www.myassignmenthelp.net
Dictionaries
• Some key-value sets• Dictionaries tend to be mutable
>>> x = {1 : ‘Welcome', ‘Two' : 32, ‘Hi' : [4,5,6]}>>> x{1: ‘Welcome', ‘Two': 32, ‘Hi': [1, 2, 3]}>>> x[‘Hi'][4,5,6]
www.myassignmenthelp.net
Standard Library• Core:– operating system, sys, string, StringIO, struct, pickle etc
• Regular expressions:– re module, Perl-5 style patterns as well as matching
rules• Web:– socket, rfc822, httplib, htmllib etc
• Miscellaneous:– pdb – Tkinter, audio etc
www.myassignmenthelp.net
Thank You
www.myassignmenthelp.net