Presentation is loading. Please wait.

Presentation is loading. Please wait.

Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data.

Similar presentations


Presentation on theme: "Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data."— Presentation transcript:

1 Identifiers and Assignment Statements

2 Data structures In any programming language you need to refer to data The simplest way is with the actual data value, like “Joe”, 23.4, True Those are called constants or literals – they stand for themselves More often you give the data a name (think of a variable name) Data also has a type = integer, float, string, Boolean Every piece of data has some space in RAM (an address) A data structure is the collection of the data’s name, its value, its type and its address. We’ll be working with simple variables for a long time, then we’ll add in lists and objects.

3 Naming things You need an identifier to name something in your program This is most often a variable but it could be a function also Every language has rules for making identifiers An identifier has to being with an alphabetic character or the underscore character _ There can be more characters in the identifier, those can be alphabetic, numeric or the underscore character Upper or lower case alphabetic characters are allowed

4 Case Sensitivity and meaningful identifiers Python is CASE SENSITIVE – upper case and lower case alphabetic characters are considered different characters Use meaningful identifiers as much as possible. Short ones like T1 and q are not conveying much information Some people like to use the underscore character to “break” the identifier into words “number_students” “total_quality_points” Some people like to use upper case letters to do the same thing “numberStudents”, “totalQualityPoints” Do not use Python keywords as identifiers. Python will sometimes let you but it is confusing!

5 Assignment statements Syntax is simple identifier = expression Python does allow more than one identifier on the left, see “Simultaneous Assignments” for more information Semantics: evaluate the expression on the right and then assign the value to the identifier on the left The expression can be as simple as a literal or more complex by using function calls, list indexing, arithmetic operators, etc. Simple statement but VERY powerful! Most programs do their work by moving things around in memory. This statement is how it is done!

6 Simultaneous assignments (Only in Python) If you use more than one identifier on the left hand side of an assignment statement, you can store more than one thing. Example: x, y = 5, 4 Semantics: x gets the 5 and y gets the 4 You have to be careful – If the right hand side does not yield as many values as the left hand side expects, it causes a crash.


Download ppt "Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data."

Similar presentations


Ads by Google