Simple statement<\/strong><\/p>\nA simple statement is comprised within a single logical line. Several simple statements may occur on a single physical line separated by semicolons. The extended BNF notation describing syntax for simple statement is:<\/p>\n
simple__stmt : := expression_stmt\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 | assert_stmt \r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 | assignment_stmt \r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 | augmented_assignment_stmt \r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 | pass_stmt \r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 | del_stmt\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 | print_stmt \r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 | return_stmt\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 | yield_stmt \r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 | raise_stmt\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 | break_stmt \r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 | continue_stmt\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 | import_stmt \r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 | global_stmt \r\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 | exec_stmt<\/pre>\nThis book will discuss some of the simple statements.<\/p>\n
Expression statement<\/strong><\/p>\nAn expression in a programming language is a combination of values, constants, variables, operators, functions etc. that are interpreted according to the particular rules of precedence for a particular programming language, which computes and then returns another value. This process is called evaluation. An expression statement evaluates the expression list (which may be a single expression).<\/p>\n
expression_stmt : := expression_list<\/pre>\nThe following are examples of expression statements and their evaluation.<\/p>\n
>>> 4 \r\n4\r\n>>> 4==4 \r\nTrue \r\n>>> 2+6 \r\n8\r\n>>> ' Hi ' * 3\u00a0\r\n' HiHiHi '<\/pre>\nAssignment statement<\/strong><\/p>\nAssignment statements are used to (re)bind names to values and to modify attributes or items of mutable objects. The following example shows binding value 4 to object (or name) a.<\/p>\n
>>> a=4<\/pre>\nPass statement<\/strong><\/p>\nThe pass statement is a null operation, nothing happens when it is executed. It is useful as a placeholder when a statement is required syntactically, but no code needs to be executed.<\/p>\n
pass_stmt\u00a0 : : =\u00a0 \" pass \"<\/pre>\nThe following example defines a function f and does nothing.<\/p>\n
>>> def f ( arg ) :\r\n. . .\u00a0 \u00a0 \u00a0 pass\r\n. . .<\/pre>\nDel statement<\/strong><\/p>\nThis statement deletes each target in target_list from left to right.<\/p>\n
del_stmt : := \" del \" target_list<\/pre>\nDeletion of a name removes the binding of that name from the local or global namespace, depending on whether the name occurs in a global statement in the same code block. If the name is unbound, a NameError exception will be raised.<\/p>\n
>>> a = [ -1 , 1 , 66\u00a0 .25 , 333 , 333 , 1234 . 5 ]\r\n>>> del a [ 0 ]\r\n>>> a\r\n[ 1 , 66 . 25 , 333 ;\u00a0 333 , 1234 . 5 ]\r\n>>> del a [ 2 : 4 ]\r\n>>> a\r\n[ 1 , 66 . 25 , 1234 . 5 ]\r\n>>> del a [ : ]\r\n>>> a\r\n[ ]\r\n>>> a = [ -1 , 1 , 66 . 25 , 333 , 333 , 1234 . 5 ]\r\n>>> del a\r\n>>> a\r\n\r\nTraceback ( most recent call last ) :\r\n File \" <pyshell#24> \" , line 1 , in <module> \r\n a\r\nNameError: name ' a ' is not defined<\/pre>\nPrint statement<\/strong><\/p>\nThe print statement evaluates each expression and then writes the resulting object to standard output (computer screen). If an object is not a string, it is first converted to a string using the rules for string conversion, the resulting or original string is then written. Space is written before each object is (converted and) written unless the output system believes it is positioned at the beginning of a line. A ‘ \\n’ character is written at the end unless the print statement ends with a comma. If only the print keyword is there in the print statement, then only the ‘ \\ n ‘ character is written. Following is a script “print_example.py”, having the following code:<\/p>\n
a=20 \r\nprint ' hi ' , 5 , a \r\nprint ' bye ' , 10 , a \r\nprint \r\nprint ' hi ' , 5 , a ,\r\nprint ' bye ' , 10 , a ,<\/pre>\nOutput after running the script is:<\/strong><\/p>\n>>> runfile ( ' C : \/ Temp \/ print_example . py ' , wdir=r ' C : \/ Temp ' ) \r\nhi 5 20 \r\nbye 10 20\r\n\r\nhi 5 20 bye 10 20<\/pre>\nReturn statement<\/strong><\/p>\nThe return statement leaves the current function call with the expression_list (or None) as the return value.<\/p>\n
return_stmt : := \" return \" [ expression_list ]<\/pre>\nThe following script ” addition_example . py ” demonstrate the use of return statement.<\/p>\n
def summation ( arg1 , arg2 ) :\r\n return arg1+arg2\r\n\r\nprint ' Sum is : ' , summation ( 1 , 2 )\r\n\r\ndef summation ( arg1 , arg2 ) : # The function return None\r\n print ' Sum is: ' , arg1+arg2\r\n\r\nsummation ( 3 , 4 ) \r\nprint summation ( 3 , 4 )\r\n\r\ndef summation ( arg1 , arg2 ) : # The function return None\r\nprint 'Sum is: ',arg1+arg2\r\nreturn\r\n\r\nsummation ( 5 , 6 ) \r\nprint summation ( 5 ,6)\r\n\r\ndef summation(argl,arg2): # The function return None\r\n print ' Sum is: ' , arg1+arg2\r\n return None\r\n\r\nsummation ( 7 , 8 ) \r\nprint summation ( 7 , 8 )\r\n\r\ndef summation ( arg1 , arg2) : \r\ndef add ( arg1 , arg2) : \r\n return arg1+arg2 \r\nreturn add (arg1 , arg2 )\r\n\r\nprint ' Sum is : ' , summation ( 9 , 10)<\/pre>\nThe output after running the script is:<\/strong><\/p>\n>>> runfile ( ' C : \/ Temp \/ addition_example . py ' , . wdir=r ' C : \/ Temp ' )\r\nSum is: 3\r\nSum is: 7 \r\nSum is: 7\r\nNone\r\nSum is: 11\r\nSum is: 11\r\nNone\r\nSura is: 15\r\nSum is: 15\r\nNone\r\nSum is: 19<\/pre>\nBreak statement<\/strong><\/p>\nThe break statement terminates the nearest enclosing loop, skipping the optional else clause if the loop has one.<\/p>\n
break_stmt : : = \" break \"<\/pre>\nIf a for loop is terminated by break, the loop control target keeps its current value. The following script ” break_example . py ” demonstrates the use of the break statement.<\/p>\n
a=5\r\nfor i in range ( 10 ) : \r\n if i==a: \r\n break \r\n else:\r\n print i\r\n\r\nprint i<\/pre>\nThe output after running the script is:<\/strong><\/p>\n>>> runfile ( ' C : \/ Temp \/ addition_example . py ' , wdir= r ' C : \/ Temp ' )\r\n0 \r\n1\r\n2\r\n3\r\n3 \r\n5<\/pre>\nContinue statement<\/strong><\/p>\nThe continue statement makes the current nearest enclosing loop skip one iteration and executes the remaining ones.<\/p>\n
continue_stmt : : = \" continue \"<\/pre>\nThe following script ” continue_example . py ” demonstrate the use of the continue statement.<\/p>\n
for i in range ( 10 ) : \r\n if i>4 and i<8 : \r\n continue \r\nelse: \r\n print i<\/pre>\nThe output after running the script is:<\/strong><\/p>\n>>> runfile ( ' C : \/ Temp \/ continue_example . py ' , wdir= r ' C : \/ Temp ' )\r\n0\r\n1\r\n2\r\n3\r\n4\r\n8\r\n9<\/pre>\nImport statement<\/strong><\/p>\nDefinitions (variables, function definitions, etc.) from one module can be imported into another module using an import statement. For more information, please refer to chapter 5.<\/p>\n
Global statement<\/p>\n
The global statement is a declaration that makes listed identifiers to be interpreted as global. This will become clearer by referring to section 3.2.5.<\/p>\n
global_stmt : := \" global \" identifier ( \" , \" identifier) *<\/pre>\n","protected":false},"excerpt":{"rendered":"In this Page, We are Providing Python Programming \u2013 Simple statement. Students can visit for more Detail and Explanation of Python Handwritten Notes\u00a0Pdf. Python Programming \u2013 Simple statement Simple statement A simple statement is comprised within a single logical line. Several simple statements may occur on a single physical line separated by semicolons. The extended …<\/p>\n
Python Programming \u2013 Simple statement<\/span> Read More »<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[5],"tags":[],"yoast_head":"\nPython Programming \u2013 Simple statement - Python Programs<\/title>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n\t\n