Python Guide V1.2.11

Charscharslistabc if6r6else blocks ifcondition

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: he value used in calling myFunc! —indented lines are executed on call —return!y returns the value y as the results of the call! • def!vectorLength(x,y):! !!!!return!m.sqrt(x!*!x!+!y!*6y)! • vectorLength(3,4)! !5.0! • def!first3Powers(n):!#6multiple6returns! !!!!return!(n,!n!*!n,!n!*!n!*!n)! • x1,!x2,!x3!=!first3Powers(6.2)! Local and global variables • a variable defined in the Python shell is global • you can access it and use its value in a function • a variable assigned a value in a function definition is local; it exists only during function execution • declare a variable global inside a function and then you can assign to the global variable of that name: global!CHARS;!CHARS!=!list("abc") if6R6else blocks! • if!condition :!!!!#!if!statement! !!!!indented lines! • elif!condition :!!#!elif!optional,!repeated! !!!!indented lines! • else6:!!!!!!!!!!#!else!optional! !!!!indented lines! • Python executes the first section that has a True6 condition, or else the else statement if present Strings: convert t...
View Full Document

This document was uploaded on 02/14/2014 for the course COMP 1012 at Manitoba.

Ask a homework question - tutors are online