Chapter 1 Review Of Python Basics - WordPress

1y ago
13 Views
2 Downloads
1.59 MB
75 Pages
Last View : 1m ago
Last Download : 3m ago
Upload by : Mika Lloyd
Transcription

Review of Python basicsCBSE Syllabus BasedClass -12CHAPTER -1ByNeha TyagiPGT CSKV 5 Jaipur II ShiftNeha Tyagi, KV 5 Jaipur II Shift

Python (a computer language) In last class we have learned about Python. In this class we willlearn Python with some new techniques. We know that Python is a powerful and high level language and it isan interpreted language. Python gives us two modes of working-– Interactive mode– Script modeScriptModeInteractiveModeNeha Tyagi, KV 5 Jaipur II Shift

Python (a computer language) It is possible to develop various Apps with Python like––––––GUI AppsWeb AppsGamesDBMS AppsScripting etc.Python (a computer language)- LimitationsThere are few limitations in Python which can be neglected because of itsvast usage.It is not a Fast Language.Libraries are very less.It is week in Type binding.It is not easy to convert in some other language.Neha Tyagi, KV 5 Jaipur II Shift

Tokens Token- is the smallest unit of any programming language.It is also known as Lexical Unit. Types of token arei.ii.iii.iv.v.KeywordsIdentifiers s are those words which providesa special meaning to interpreter.These are reserved for specific functioning.These can not be used as identifiers,variable name or any other purpose.Available keywords in Python are-Neha Tyagi, KV 5 Jaipur II Shift

Identifiers These are building blocks of a program and are used to give names to different parts/blocks of a program like - variable, objects, classes,functions.An identifier may be a combination of letters and numbers.An identifier must begin with an alphabet or an underscore( ).Subsequent letters may be numbers(0-9).Python is case sensitive. Uppercase characters are distinct fromlowercase characters (P and p are different for interpreter).Length of an Identifier is unlimited.Keywords can not be used as an identifier.Space and special symbols are not permitted in an identifier name exceptan underscore( ) sign.Some valid identifiers are – Myfile, Date9 7 17, Z2T0Z9, DS, CHK FILE13. Some invald identifiers are – DATA-REC, 29COLOR, break, My.File.Neha Tyagi, KV 5 Jaipur II Shift

Literals / Values Literals are often called Constant Values. Python permits following types of literals –String literals - “Pankaj”–Numeric literals – 10, 13.5, 3 5j–Boolean literals – True or False–Special Literal None–Literal collectionsString LiteralsString Literal is a sequence of characters that can be a combination ofletters, numbers and special symbols, enclosed in quotation marks,single, double or triple(“ “ or ‘ ‘ or “’ ‘”).In python, string is of 2 typesSingle line stringText “Hello World” or Text ‘Hello World’Multi line stringText ‘hello\world’orNeha Tyagi, KV 5 Jaipur II ShiftText ‘’’helloword ‘’’

संजीव भदौरिया, के० वव० बािाबंकीNumeric Literals Numeric values can be of three types -– int (signed integers) Decimal Integer Literals – 10, 17, 210 etc. Octal Integer Literals - 0o17, 0o217 etc. Hexadecimal Integer Literals – 0x14, 0x2A4, 0xABD etc.– float ( floating point real value) Fractional Form – 2.0, 17.5 -13.5, -.00015 etc. Exponent Form - -1.7E 8, .25E-4 etc.– complex (complex numbers) 3 5i etc.Boolean LiteralsSpecial LiteralsIt can contain either of only two values – True orFalse A True B False None, which means nothing (no value). X NoneNeha Tyagi, KV 5 Jaipur II Shift

Operators An Operator is a symbol that trigger some action whenapplied to identifier (s)/ operand (s) Therefore, an operator requires operand (s) to computeupon. example :c a bHere, a, b, c are operands and operators are and whichare performing differently.Punctuators In Python, punctuators are used to construct the programand to make balance between instructions and statements.Punctuators have their own syntactic and semanticsignificance. Python has following Punctuators ‘, ”, #, \, (, ), [, ], {, }, @. ,, :, . , Neha Tyagi, KV 5 Jaipur II Shift

DATA TYPES Data can be of any type like- character, integer, real, string.Anything enclosed in “ “ is considered as string in Python.Any whole value is an integer value.Any value with fraction part is a real value.True or False value specifies boolean value.Python supports following core data y(int like10, 5) (float like 3.5, 302.24) (complex like 3 5j)(like “pankaj”, ‘pankaj’, ‘a’, “a” )like [3,4,5,”pankaj”] its elements are Mutable.like(3,4,5,”pankaj”) its elements are immutable.like {‘a’:1, ‘e’:2, ‘I’:3, ‘o’:4, ‘u’:5} where a,e,i,o,u are keysand 1,2,3,4,5 are their values.Neha Tyagi, KV 5 Jaipur II Shift

CORE DATA TYPESGraphical ViewCOREDATA sStringTupleBooleanNeha Tyagi, KV 5 Jaipur II ShiftMappingsListDictionary

Variables and ValuesAn important fact to know is– In Python, values are actually objects.– And their variable names are actually their reference names.Suppose we assign 10 to a variable A.A 10Here, value 10 is an object and A is its reference name.10ReferencevariableNeha Tyagi, KV 5 Jaipur II ShiftObject

Variables and ValuesIf we assign 10 to a variable B,B will refer to same object.Here, we have two variables,but with same location.10ReferencevariableNow, if we change value of B likeB 20Then a new object will be created witha new location 20 and this object will bereferenced by B.Neha Tyagi, KV 5 Jaipur II ShiftObject2010

Mutable and Immutable TypesFollowing data types comes under mutable andimmutable types Mutable (Changeable)– lists, dictionaries and sets. Immutable (Non-Changeable)– integers, floats, Booleans, strings and tuples.Neha Tyagi, KV 5 Jaipur II Shift

Operators The symbols that shows a special behavior oraction when applied to operands are calledoperators. For ex- , - , , etc. Python supports following operatorsI.II.III.IV.V.VI.Arithmetic OperatorRelation OperatorIdentity OperatorsLogical OperatorsBitwise OperatorsMembership OperatorsNeha Tyagi, KV 5 Jaipur II Shift

Operator Associativity In Python, if an expression or statement consistsof multiple or more than one operator thenoperator associativity will be followed from left-toright. In above given expression, first 7*8 will be calculated as 56, then 56 willbe divided by 5 and will result into 11.2, then 11.2 again divided by 2and will result into 5.0.*Only in case of **, associativity will be followed fromAbove given example will be calculated as 3**(3**2).Neha Tyagi, KV 5 Jaipur II Shiftright-to-left.

Type Casting As we know, in Python, an expression may be consists ofmixed datatypes. In such cases, python changes data typesof operands internally. This process of internal data typeconversion is called implicit type conversion. One other option is explicit type conversion which is like datatype (identifier)For exa “4”b int(a)Another exIf a 5 and b 10.5 then we can convert a to float.Like d float(a)In python, following are the data conversion functions(1) int ( ) (2) float( ) (3) complex( ) (4) str( ) (5) bool( )Neha Tyagi, KV 5 Jaipur II Shift

Taking Input in Python In Python, input () function is used to take input which takes input in theform of string. Then it will be type casted as per requirement. For ex- tocalculate volume of a cylinder, program will be as- Its output will be as-Neha Tyagi, KV 5 Jaipur II Shift

Types of statements in Python In Python, statements are of 3 types» Empty Statements pass» Simple Statements (Single Statement) name input (“Enter your Name “) print(name) etc.» Compound Statements Compound Statement Header : IndentedBodycontainingstatements/compound statements multiplesimple Here, Header line starts with the keyword and ends at colon (:). The body consists of more than one simple Python statements orcompound statements.Neha Tyagi, KV 5 Jaipur II Shift

Statement Flow Control In a program, statements executes in sequentialmanner or in selective manner or in iterativemanner.SequentialSelectiveIterativeNeha Tyagi, KV 5 Jaipur II Shift

Python -----if Statements In Python, if statement is used to select statementfor processing. If execution of a statement is to bedone on the basis of a condition, if statement is tobe used. Its syntax isif condition :statement(s)like -Neha Tyagi, KV 5 Jaipur II Shift

Python---if-else Statements If out of two statements, it is required to select onestatement for processing on the basis of a condition,if-else statement is to be used. Its syntax isif condition :statement(s) when condition is trueelse:statement(s) when condition is falselike -Neha Tyagi, KV 5 Jaipur II Shift

Nested If -elseNeha Tyagi, KV 5 Jaipur II Shift

Loop/Repetitive Task/IterationThese control structures are used for repeatedexecution of statement(s) on the basis of a condition.Loop has 3 main components1. Start (initialization of loop)2. Step (moving forward in loop )3. Stop (ending of loop)Python has following loops– for loop– while loopNeha Tyagi, KV 5 Jaipur II Shift

range () Function In Python, an important function is range( ). itssyntax isrange ( lower limit , upper limit )If we write - range (0,5 )Then a list will be created with the values [0,1,2,3,4] i.e. fromlower limit to the value one less than ending limit.range (0,10,2) will have the list [0,2,4,6,8].range (5,0,-1) will have the list [5,4,3,2,1].Neha Tyagi, KV 5 Jaipur II Shift

Jump Statementsbreak Statementwhile test-condition :statement1if condition :breakstatement2statement3Statement4statement5for var in sequence :statement1if condition :breakstatement2statement3Statement4statement5Neha Tyagi, KV 5 Jaipur

Jump Statementsbreak StatementOutputOutputNeha Tyagi, KV 5 Jaipur II Shift

in and not in operator in operator3 in [1,2,3,4] will return True.5 in [1,2,3,4] will return False.– not in operator5 not in [1,2,3,4] will return True.Neha Tyagi, KV 5 Jaipur II Shift

Jump Statementscontinue StatementOutput of both the program---Neha Tyagi, KV 5 Jaipur II Shift

Nested LoopOUTPUTNeha Tyagi, KV 5 Jaipur II Shift

String Creation String can be created in following ways1. By assigning value directly to the variableString Literal2. By taking InputInput ( ) always return input inthe form of a string.Neha Tyagi, KV 5 Jaipur II Shift

Traversal of a string Process to access each and every character of a stringfor the purpose of display or for some other purpose iscalled string traversal.OutputProgram to print a String after reverse -OutputNeha Tyagi, KV 5 Jaipur II Shift

String Operators There are 2 operators that can be used to work uponstrings and *.» (it is used to join two strings) Like - “tea” “pot” will result into “teapot” Like- “1” “2” will result into “12” Like – “123” “abc” will result into “123abc”»*(it is used to replicate the string) like - 5*”@” will result into “@@@@@” Like - “go!” * 3 will result “go!go!go!”note : - “5” * “6” expression is invalid.Neha Tyagi, KV 5 Jaipur II Shift

String Slicing Look at following examples Reverse index-14-13-12-11-10-9-8-7-6-5-4-3-2-1word “RESPONSIBILITY”word[ 0 : 14 ] will result into‘RESPONSIBILITY’word[ 0 : 3] will result into‘RES’word[ 2 : 5 ] will result into‘SPO’word[ -7 : -3 ] will result into‘IBIL’word[ : 14 ] will result into‘RESPONSIBILITY’word[ : 5 ] will result into ‘RESPO’word[ 3 : ] will result into ‘PONSIBILITY’Neha Tyagi, KV 5 Jaipur II Shift

String FunctionsString.capitalize()Converts first character to Capital LetterString.find()Returns the Lowest Index of SubstringString.index()Returns Index of SubstringString.isalnum()Checks Alphanumeric CharacterString.isalpha()Checks if All Characters are AlphabetsString.isdigit()Checks Digit CharactersString.islower()Checks if all Alphabets in a String.are LowercaseString.isupper()returns if all characters are uppercase charactersString.join()Returns a Concatenated StringString.lower()returns lowercased stringString.upper()returns uppercased stringlen()Returns Length of an Objectord()returns Unicode code point for Unicode characterreversed()returns reversed iterator of a sequenceslice()creates a slice object specified by range()Neha Tyagi, KV 5 Jaipur II Shift

List Creation List is a standard data type of Python. It is a sequence whichcan store values of any kind. List is represented by square brackets “ [ ] “For ex []Empty list [1, 2, 3]integers list [1, 2.5, 5.6, 9]numbers list (integer and float) [ ‘a’, ‘b’, ‘c’]characters list [‘a’, 1, ‘b’, 3.5, ‘zero’] mixed values list [‘one’, ’two’, ’three’] string list In Python, only list and dictionary are mutable data types, restof all the data types are immutable data types.Neha Tyagi, KV 5 Jaipur II Shift

List Creation List can be created in following ways Empty list L [] list can also be created with the following statementL list( ) Long listseven [0, 2, 4, 6, 8, 10 ,12 ,14 ,16 ,18 ,20 ] Nested list L [ 3, 4, [ 5, 6 ], 7]Another methodNeha Tyagi, KV 5 Jaipur II ShiftThis is a Tuple

List Creation-As we have seen in the exampleThat when we have suppliedvalues as numbers to a list even thenThey have automatically converted to string– If we want to pass values to a list in numeric form then we have to writefollowing function eval(input())L eval(input(“Enter list to be added “))eval ( ) function identifies type of the passed string and then return it.Another exampleString ValuesNeha Tyagi, KV 5 Jaipur II Shift

Accessing a ListFirst we will see the similarities between a List and a String.List is a sequence like a string.List also has index of each of its element.Like string, list also has 2 index, one for forward indexing (from0, 1, 2, 3, .to n-1) and one for backward indexing(from -n to 1). In a list, values can be accessed like string. Forward index 0 1 2 3 4 5List R ESP O NBackward index -14 -13 -12 -11 -10 -9678910 11 12 13SIBILITY-8-7-6-5-4-3-2-1Neha Tyagi, KV 5 Jaipur II Shift

Accessing a List len( ) function is used to get the length of a list.Important 1:membershipoperator (in, not in) worksin list similarly as they workin other sequence. L[ i ] will return the values exists at i index. L [ i : j ] will return a new list with the values from i index to j index excludingj index.Important 2: operatoradds a list at the end ofother list whereas *operator repeats a list.Neha Tyagi, KV 5 Jaipur II Shift

Difference between a List and a String Main difference between a List and a string is that string isimmutable whereas list is mutable. Individual values in string can’t be change whereas it ispossible with list.Value didn’tchange in string.Error shown.Value got changedin list specifyinglist is mutableNeha Tyagi, KV 5 Jaipur II Shift

Traversal of a list Traversal of a list means to access and process each andevery element of that list. Traversal of a list is very simple with for loop –for item in list :*Python supports UNICODE thereforeoutput in Hindi is also possibleNeha Tyagi, KV 5 Jaipur II Shift

List Operations ( , *) Main operations that can be performed on lists are joining list,replicating list and list slicing. To join Lists, operator , is used which joins a list at the end ofother list. With operator, both the operands should be of listtype otherwise error will be generated. To replicate a list, * operator , is used.Neha Tyagi, KV 5 Jaipur II Shift

List Operations (Slicing) To slice a List, syntax isseq list [ start : stop ] Another syntax for List slicing is –seq list[start:stop:step]Neha Tyagi, KV 5 Jaipur II Shift

Use of slicing for list Modification Look carefully at following examples-New value is being assigned here.Here also, new value is being assigned.See the difference between both the results.144 is a value and not a sequence.Neha Tyagi, KV 5 Jaipur II Shift

List Functions and Methods– Python provides some built-in functions for list manipulation– Syntax is like list-object . method-name FunctionDetailsList.index( item )Returns the index of passed items.List.append( item )Adds the passed item at the end of list.List.extend( list )Append the list (passed in the form of argument) at the end of listwith which function is called.List.insert( pos , item )Insert the passed element at the passed position.List.pop( index )Delete and return the element of passed index. Index passing isoptional, if not passed, element from last will be deleted.List.remove( value )It will delete the first occurrence of passed value but does notreturn the deleted value.Neha Tyagi, KV 5 Jaipur II Shift

List Functions and MethodsFunctionDetailsList.clear ( )It will delete all values of list and gives an empty list.List.count ( item )It will count and return number of occurrences of the passed element.List.reverse ( )It will reverse the list and it does not create a new list.List.sort ( )It will sort the list in ascending order. To sort the list in descendingorder, we need to write----- list.sort(reverse True).Neha Tyagi, KV 5 Jaipur II Shift

Creation of Tuple In Python, “( )” parenthesis are used for tuple creation.()empty tuple( 1, 2, 3)integers tuple( 1, 2.5, 3.7, 7)numbers tuple(‘a’, ’b’, ’c’ )characters tuple( ‘a’, 1, ‘b’, 3.5, ‘zero’)mixed values tuple(‘one’, ’two’, ’three’, ’four’)string tuple*Tuple is an immutable sequence whose values can not be changed.Neha Tyagi, KV 5 Jaipur II Shift

Creation of TupleLook at following examples of tuple creation carefully Empty tuple: Single element tuple: Long tuple: Nested tuple:Neha Tyagi, KV 5 Jaipur II Shift

Creation of Tupletuple() function is used to create a tuple from other sequences.See examplesTuple creation from stringTuple creation from listTuple creation from inputAll these elements are ofcharacter type. To havethese in different types,need to write followingstatement.Tuple eval(input(“Enterelements”))Neha Tyagi, KV 5 Jaipur II Shift

Accessing a Tuple In Python, the process of tuple accessing is same aswith list. Like a list, we can access each and everyelement of a tuple. Similarity with List- like list, tuple also has index. Allfunctionality of a list and a tuple is same except mutability.Forward index 0Tuple RBackward index -1412345678910 11 12 13ESPONSIBILITY-13-12-11-10-9-8-7-6-5-4-3-2-1 len ( ) function is used to get the length of tuple.Neha Tyagi, KV 5 Jaipur II Shift

Accessing a Tuple Indexing and Slicing: T[ i ] T[ i : j ] T[i:j:n]returns the item present at index i.returns a new tuple having all the items of T fromindex i to j.returns a new tuple having difference of n elementsof T from index i to j.index i to j. Membership operator: Working of membership operator “in” and “not in” is same asin a list. (for details see the chapter- list manipulation). Concatenation and Replication operators: operator adds second tuple at the end of first tuple. * operator repeatselements of tuple.Neha Tyagi, KV 5 Jaipur II Shift

Accessing a Tuple Accessing Individual elements- Traversal of a Tuple –for item in tuple :#to process every element.OUTPUTNeha Tyagi, KV 5 Jaipur II Shift

Tuple Operations Tuple joining Both the tuples should be there to addwith . Some errors in tuple joining In Tuple numberIn Tuple complex numberIn Tuple stringIn Tuple listTuple (5) will also generate error because when adding a tuple witha single value, tuple will also be considered as a value and not atuple. Tuple Replication-Neha Tyagi, KV 5 Jaipur II Shift

Tuple SlicingTuple will show till last element of list irrespective of upperlimit.Every alternate element will be shown.Every third element will be shown.Neha Tyagi, KV 5 Jaipur II Shift

Dictionary Creation To create a dictionary, it is needed to collect pairs ofkey:value in “{ }”. dictionary-name { key1 : value1 , key2 : value2 , key3 : value3 . . . }Example:teachers {“Rajeev”:”Math”, SB”:”CS”}In above given example :Key-value �“SB”:”CS”“SB”“CS”Neha Tyagi, KV 5 Jaipur II Shift

Dictionary Creation Some examples of Dictionary areDict1 { }# this is an empty dictionary without any element.DayofMonth { January”:31, ”February”:28, ”March”:31, ”April”:30, ”May”:31, ”June”:30,”July”:31, ”August”:31, ”September”:30, ”October”:31, ”November”:30,”December”:31}FurnitureCount { “Table”:10, “Chair”:13, “Desk”:16, “Stool”:15, “Rack”:15 }– By above examples you can easily understand about the keysand their values.– One thing to be taken care of is that keys should always be ofimmutable type.Note: Dictionary is also known as associative array or mappingor hashes .Neha Tyagi, KV 5 Jaipur II Shift

Dictionary Creation– Keys should always be of immutable type.– If you try to make keys as mutable, python shown error in it.For example-Here key is a list which isof mutable type.Here error shows that you are trying to create a keyof mutable type which is not permitted.Neha Tyagi, KV 5 Jaipur II Shift

Accessing a Dictionary To access a value from dictionary, we need to use keysimilarly as we use an index to access a value from a list. We get the key from the pair of Key: value.teachers {“Rajeev”:”Math”, SB”:”CS”} If we execute following statement from above example- We have selected key “Rajeev” and on printing it, Math gotprinted. Another exampleIf we access a non-key, error will come.Neha Tyagi, KV 5 Jaipur II Shift

Traversal of a Dictionary To traverse a Dictionary, we use for loop. Syntax isfor item in dictionary :Here, notable thing is that every key of each pair ofdictionary d is coming in k variable of loop. After thiswe can take output with the given format and withprint statement.Assignment : Develop a dictionary of your friends in which keywill be your friend’s name and his number will be its value.Neha Tyagi, KV 5 Jaipur II Shift

Traversal of Dictionary To access key and value we need to use keys() andvalues().for example- d.keys( ) function will display only key. d.values ( ) function will display value only.Neha Tyagi, KV 5 Jaipur II Shift

Features of Dictionary1. Unordered set: dictionary is a unordered collection of key:value pairs.2. Not a sequence: like list, string and tuple , it is not a sequence becauseit is a collection of unordered elements whereas a sequence is a collectionof indexed numbers to keep them in order.3. Keys are used for its indexing because according to Python key can be ofimmutable type. String and numbers are of immutable type and thereforecan be used as a key. Example of keys are as under-Key of a Dictionary should always be ofimmutable type like number, string or tuplewhereas value of a dictionary can be of any type.Neha Tyagi, KV 5 Jaipur II Shift

Features of Dictionary4. Keys should be unique : Because keys are used to identifyvalues so they should be unique.5. Values of two unique keys can be same.6. Dictionary is mutable hence we can change value of a certainkey. For this, syntax is dictionary [ key ] value 4. Internally it is stored as a mapping. Its key:value areconnected to each other via an internal function called hashfunction**. Such process of linking is knows as mapping.**Hash-function is an internal algorithm to link a and itsvalue.Neha Tyagi, KV 5 Jaipur II Shift

Working with Dictionary Here we will discuss about various operation of dictionary like elementadding, updation, deletion of an element etc. but first we will learn creationof a dictionary. Dictionary initialization- For this we keep collection of pairs ofkey:value separated by comma (,) and then place thiscollection inside “{ }”. Addition of key:value pair to an empty dictionary. There aretwo ways to create an empty dictionary1. Employee { }2. Employee dict( )After that use following syntax- dictionary [ key ] value Neha Tyagi, KV 5 Jaipur II Shift

Working with Dictionary3. Creation of a Dictionary with the pair of name andvalue: dict( ) constructor is used to create dictionarywith the pairs of key and value. There are variousmethods for thisI.By passing Key:value pair as an argument:The point to be noted is that here no inverted commas were placed inargument but they came automatically in dictionary.II. By specifying Comma-separated key:value pair-Neha Tyagi, KV 5 Jaipur II Shift

Working with DictionaryIII. By specifying Keys and values separately:For this, we use zip() function in dict ( ) constructor-IV. By giving Key:value pair in the form of separate sequence:By passing ListBy passing tuple of a listBy passing tuple of tupleNeha Tyagi, KV 5 Jaipur II Shift

Adding an element in Dictionaryfollowing syntax is used to add an element in Dictionary-Nesting in Dictionarylook at the following example carefully in which element of a dictionary isa dictionary itself.Neha Tyagi, KV 5 Jaipur II Shift

Updation in a Dictionaryfollowing syntax is used to update an element in Dictionary dictionary [ ExistingKey ] value WAP to create a dictionary containing names of employee as key and their salary asvalue.OutputNeha Tyagi, KV 5 Jaipur II Shift

Deletion of an element from a Dictionaryfollowing two syntaxes can be used to delete an element form aDictionary. For deletion, key should be there otherwise pythonwill give error.1. del dictionary [ key ]- it only deletes the value anddoes not return deleted value.Value did not return after deletion.2. dictionary .pop( key ) it returns the deleted valueafter deletion.Value returned after deletion.If key does not match, givenmessage will be printed.Neha Tyagi, KV 5 Jaipur II Shift

Detection of an element from a DictionaryMembership operator is used to detect presence of an elementin a Dictionary.1. key in dictionary it gives true on finding the key otherwise gives false.2. key not in dictionary it gives true on not finding the key otherwise gives false.False* in and not in does not applyon values, they can only workwith keys.Neha Tyagi, KV 5 Jaipur II Shift

Pretty Printing of a DictionaryTo print a Dictionary in a beautify manner, we need to importjson module. After that following syntax of dumps ( ) will be used.json.dumps( ,indent n )Neha Tyagi, KV 5 Jaipur II Shift

Program to create a dictionary by counting words in a lineHere a dictionary iscreated of wordsand their frequency.Neha Tyagi, KV 5 Jaipur II Shift

Dictionary Function and Method1. len( ) Method : it tells the length of dictionary.2. clear( ) Method : it empties the dictionary.3. get( ) Method : it returns value of the given key.It works similarly as dictionary [ key ]On non finding of a key, default message can begiven.Neha Tyagi, KV 5 Jaipur II Shift

Dictionary Function and Method4. items( ) Method : it returns all items of a dictionary in the formof tuple of (key:value).5. keys( ) Method : it returns list of dictionary keys.6. values( ) Method : it returns list of dictionary values.Neha Tyagi, KV 5 Jaipur II Shift

Dictionary Function and Method7. Update ( ) Method: This function merge the pair of key:valueof a dictionary into other dictionary. Change and addition inthis is possible as per need. Example-In the above given example, you can see that change is done inthe values of similar keys whereas dissimilar keys got joined withtheir values.Neha Tyagi, KV 5 Jaipur II Shift

Thank youplease follow us on our blogwww.pythontrends.wordpress.comNeha Tyagi, KV 5 Jaipur II Shift

Python (a computer language) In last class we have learned about Python. In this class we will learn Python with some new techniques. We know that Python is a powerful and high level language and it is an interpreted language. Python gives us two modes of working- -Interactive mode -Script mode Neha Tyagi, KV 5 Jaipur II Shift

Related Documents:

Python Programming for the Absolute Beginner Second Edition. CONTENTS CHAPTER 1 GETTING STARTED: THE GAME OVER PROGRAM 1 Examining the Game Over Program 2 Introducing Python 3 Python Is Easy to Use 3 Python Is Powerful 3 Python Is Object Oriented 4 Python Is a "Glue" Language 4 Python Runs Everywhere 4 Python Has a Strong Community 4 Python Is Free and Open Source 5 Setting Up Python on .

Python 2 versus Python 3 - the great debate Installing Python Setting up the Python interpreter About virtualenv Your first virtual environment Your friend, the console How you can run a Python program Running Python scripts Running the Python interactive shell Running Python as a service Running Python as a GUI application How is Python code .

Python is readable 5 Python is complete—"batteries included" 6 Python is cross-platform 6 Python is free 6 1.3 What Python doesn't do as well 7 Python is not the fastest language 7 Python doesn't have the most libraries 8 Python doesn't check variable types at compile time 8 1.4 Why learn Python 3? 8 1.5 Summary 9

Part One: Heir of Ash Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9 Chapter 10 Chapter 11 Chapter 12 Chapter 13 Chapter 14 Chapter 15 Chapter 16 Chapter 17 Chapter 18 Chapter 19 Chapter 20 Chapter 21 Chapter 22 Chapter 23 Chapter 24 Chapter 25 Chapter 26 Chapter 27 Chapter 28 Chapter 29 Chapter 30 .

There are currently two versions of Python in use; Python 2 and Python 3. Python 3 is not backward compatible with Python 2. A lot of the imported modules were only available in Python 2 for quite some time, leading to a slow adoption of Python 3. However, this not really an issue anymore. Support for Python 2 will end in 2020.

site "Python 2.x is legacy, Python 3.x is the present and future of the language". In addition, "Python 3 eliminates many quirks that can unnecessarily trip up beginning programmers". However, note that Python 2 is currently still rather widely used. Python 2 and 3 are about 90% similar. Hence if you learn Python 3, you will likely

TO KILL A MOCKINGBIRD. Contents Dedication Epigraph Part One Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9 Chapter 10 Chapter 11 Part Two Chapter 12 Chapter 13 Chapter 14 Chapter 15 Chapter 16 Chapter 17 Chapter 18. Chapter 19 Chapter 20 Chapter 21 Chapter 22 Chapter 23 Chapter 24 Chapter 25 Chapter 26

A Python Book A Python Book: Beginning Python, Advanced Python, and Python Exercises Author: Dave Kuhlman Contact: dkuhlman@davekuhlman.org