Example: air traffic controller

Basic concepts of Python language Data types and values ...

OutlineBasic concepts of Python languageBasic concepts of Python languageData types and valuesExpressions and statementsFlow control and functionsData structures: lists, tuples, sets, dictionariesBasic input and outputJarkko Toivonen Department of Computer Science University of HelsinkiProgramming in PythonOutlineBasic concepts of Python languageData types and valuesExpressions and statementsFlow control and functionsBasic input and outputBasic data types Examples: int: 12, 0, -2 float: , , complex: 3+4j bool: True, False string:"Test string"Jarkko Toivonen Department of Computer Science University of HelsinkiProgramming in PythonOutlineBasic concepts of Python languageData types and valuesExpressions and statementsFlow control and functionsBasic input and outputConversion between types int( ) -2 float(2) int( 123 ) 123 bool(-2) True, bool(0) False str(234) 234 Jarkko Toivonen Department of Computer Science University of HelsinkiProgramming in PythonOutlineBasic concepts of Python languageData types and valuesExpressions and statementsFlow control and functionsBasic input and outputStrings 1 A sequence of characters delimitted between single ( ) or double ( ) quotes This optionality

Basic concepts of Python language Basic concepts of Python language Data types and values Expressions and statements Flow control and functions Data structures: lists, tuples, sets, dictionaries Basic input and output ... Basic data types Examples:

Tags:

  Python, Basics, Example

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of Basic concepts of Python language Data types and values ...

1 OutlineBasic concepts of Python languageBasic concepts of Python languageData types and valuesExpressions and statementsFlow control and functionsData structures: lists, tuples, sets, dictionariesBasic input and outputJarkko Toivonen Department of Computer Science University of HelsinkiProgramming in PythonOutlineBasic concepts of Python languageData types and valuesExpressions and statementsFlow control and functionsBasic input and outputBasic data types Examples: int: 12, 0, -2 float: , , complex: 3+4j bool: True, False string:"Test string"Jarkko Toivonen Department of Computer Science University of HelsinkiProgramming in PythonOutlineBasic concepts of Python languageData types and valuesExpressions and statementsFlow control and functionsBasic input and outputConversion between types int( ) -2 float(2) int( 123 ) 123 bool(-2) True, bool(0) False str(234) 234 Jarkko Toivonen Department of Computer Science University of HelsinkiProgramming in PythonOutlineBasic concepts of Python languageData types and valuesExpressions and statementsFlow control and functionsBasic input and outputStrings 1 A sequence of characters delimitted between single ( ) or double ( ) quotes This optionality is useful if a string needs to contain aquotation mark.

2 You can also achieve this by escaping thequotation mark:\"or\ Can also contain escape sequences like\nfor newline and\tfor tabulator. See page 41 of the course page for all escapesequences. Strings can be concatenated with the+operator:"compu" + "ter"results a new string computer .Jarkko Toivonen Department of Computer Science University of HelsinkiProgramming in PythonOutlineBasic concepts of Python languageData types and valuesExpressions and statementsFlow control and functionsBasic input and outputStrings 2 If you want a string to contain several lines of text, use triplequoted strings: First linesecond line Jarkko Toivonen Department of Computer Science University of HelsinkiProgramming in PythonOutlineBasic concepts of Python languageData types and valuesExpressions and statementsFlow control and functionsBasic input and outputExpressions 1 Anexpressionis a piece of Python code that results in a value It consists of values combined together with operators values can beliteralsor variables Operators include arithmetic operators, comparison operators,function calls, indexing, attribute references, among others.

3 Examples of expressions:1+2 c > 0 and c != 17/(2+ ) (1,2,3)a a < 5cos(0) [1](-1)**2 == 1 Jarkko Toivonen Department of Computer Science University of HelsinkiProgramming in PythonOutlineBasic concepts of Python languageData types and valuesExpressions and statementsFlow control and functionsBasic input and outputExpressions 2 Usually expressions don t do anything beyond resulting avalue, but sometimes an epression, typically a function call,can haveside-effects Side-effects that functions may have, should be welldocumented. Otherwise unexpected behaviour and confusioncan occur, and the reason for this is hard to pinpoint For example , the function (method)writelinehas theside-effect of changing the contents of a file. Programming without any side-effects is calledfunctionalprogramming Python is not a functional programming language , it is animperativelanguageJarkko Toivonen Department of Computer Science University of HelsinkiProgramming in PythonOutlineBasic concepts of Python languageData types and valuesExpressions and statementsFlow control and functionsBasic input and outputStatements 1 Statementsare commands that have some effect Simplest example of statements is just an expression: Usually these are function calls Are also used in interactive use: the interpreter prints thecomputed value of an expression The print statement prints the values of expressions: printexpr1, expr2.

4 Another simple statement is an assignment:variablename = expressionJarkko Toivonen Department of Computer Science University of HelsinkiProgramming in PythonOutlineBasic concepts of Python languageData types and valuesExpressions and statementsFlow control and functionsBasic input and outputVariables Variable is a name that refers to a value or anobject With the assignment operator, you can bind avariable nameto a value, and rebind it later to another value In Python typesare notattached to variable names; typesareattached to objects/ values in the memory of the computer This is runtime/dynamic typing Therefore a variable namevarcan at one time point to anstring and a few seconds later point to a complex number This can make your program a bit confusing: try to avoid itJarkko Toivonen Department of Computer Science University of HelsinkiProgramming in PythonOutlineBasic concepts of Python languageData types and valuesExpressions and statementsFlow control and functionsBasic input and outputBindings and type checking in C and PythontypeC static typingmemoryvariable_namePython dynamic typingvariable_namememorystrintJarkko Toivonen Department of Computer Science University of HelsinkiProgramming in Pytho


Related search queries