Py4Inf-02-Expressions-PrintPy4Inf-02-Expressions-Print
9页1、Variables, Expressions, and StatementsChapter 2Python for Informatics: Exploring IUnless otherwise noted, the content of this course material is licensed under a Creative Commons Attribution 3.0 License.htp:/creativecommons.org/licenses/by/3.0/.Copyright 2010- Charles R. SeveranceConstantsFixed values such as numbers, letters, and strings are caled “constants” - because their value does not changeNumeric constants are as you expectString constants use single-quotes ()or double-quotes () print 12
2、3123 print 98.698.6 print Hello worldHello worldVariablesA variable is a named place in the memory where a programmer can store data and later retrieve the data using the variable “name”Programmers get to choose the names of the variablesYou can change the contents of a variable in a later statement12.2x14 yx = 12.2y = 14100x = 100Python Variable Name RulesMust start with a letter or underscore _ Must consist of letters and numbers and underscoresCase SensitiveGood: spam eggs spam23 _speedBad: 2
3、3spam #sign var.12Different: spam Spam SPAMReserved WordsYou can not use reserved words as variable names / identifiersand del for is raise asert elif from lambda return break else global not try clas except if or while continue exec import pas yield def finaly in print Sentences or Linesx = 2x = x + 2print xVariable OperatorConstant Reserved WordAssignment StatementAssignment with expressionPrint statementAssignment StatementsWe asign a value to a variable using the asignment statement (=)An as
4、ignment statement consists of an expression on the right hand side and a variable to store the resultx = 3.9 * x * ( 1 - x )x = 3.9 * x * ( 1 - x )0.6xRight side is an expression. Once expression is evaluated, the result is placed in (asigned to) x.0.60.60.40.93A variable is a memory location used to store a value (0.6).x = 3.9 * x * ( 1 - x )0.6 0.93xRight side is an expression. Once expression is evaluated, the result is placed in (asigned to) the variable on the left side (i.e. x).0.93A varia
《Py4Inf-02-Expressions-PrintPy4Inf-02-Expressions-Print》由会员海天分享,可在线阅读,更多相关《Py4Inf-02-Expressions-PrintPy4Inf-02-Expressions-Print》请在金锄头文库上搜索。
红灰动态个性商务幻灯片模板简洁动态手势
蓝色清爽月度工作总结PPT模板简洁商务办公月度总结
动态蓝色拼图背景的工作计划PPT模板工作计划2
高架桥背景的工作计划PPT模板
Excel函数VBA教程基础入门(下)
唯美蓝色星空背景的动态工作总结PPT模板蓝色星空2
繁华城市背景的商业融资计划书PPT模板繁华城市
红灰动态个性商务幻灯片模板红灰个性商务
Py4Inf-06-Strings-PrintPy4Inf-06-Strings-Print
Py4Inf-05-IterationsPy4Inf-05-Iterations
Py4Inf-05-Iterations-PrintPy4Inf-05-Iterations-Print
Py4Inf-04-FunctionsPy4Inf-04-Functions
Py4Inf-04-Functions-PrintPy4Inf-04-Functions-Print
Py4Inf-03-ConditionalPy4Inf-03-Conditional
Py4Inf-03-Conditional-PrintPy4Inf-03-Conditional-Print
Py4Inf-02-ExpressionsPy4Inf-02-Expressions
Py4Inf-02-Expressions-PrintPy4Inf-02-Expressions-Print
Py4Inf-01-IntroPy4Inf-01-IntroPy4Inf-01-IntroPy4Inf-01-Intro
Py4Inf-01-Intro-PrintPy4Inf-01-Intro-Print
JAVA初级入门教程
2024-03-05 77页
2024-03-05 50页
2024-02-29 54页
2024-02-29 75页
2024-02-29 52页
2024-02-29 54页
2024-02-29 125页
2024-02-29 74页
2024-02-29 61页
2024-02-29 56页