Anna GE 8151 - Python Programming - Data types, variables, identifiers (1)

Unformatted text preview:

DATATYPES VARIABLES IDENTIFIERS PYTHON PROGRAMMING Variables and Identifiers A variable is an alternate name given to some memory locations It allows us to store and manipulate data in our programs In Python we can assign values to variables and update them as needed An identifier on the other hand is used to identify elements such as variables classes functions etc We give names to these elements so that we can easily identify and work with them Rules for Naming Variables and Identifiers The name should not match any Python keyword The name can consist of alphabets or numerals The name should start with a character or an underscore The name can be alphanumeric but it should start with a character or an underscore different variables The name is case sensitive so name and Name are considered In Python we have different data types to represent different kinds of values The two main categories are numbers and strings Data Types Numbers Numbers can be integers floating point numbers or complex numbers In Python we can assign values to variables without explicitly declaring their data types For example j 5 assigns the value 5 to the variable j which is automatically considered an integer We can perform arithmetic operations on these numbers just like in other programming languages Strings Strings represent sequences of characters Even a single character is treated as a string in Python We can assign string values to variables using single or double quotes Overall Python makes it simpler to work with variables and data types compared to other programming languages We can directly assign values to variables without explicitly declaring their data types These four statements declare variables and assign values to them The variable name is assigned the value python The variable washer is declared as int The variable price is declared as float The variable complex is declared as complex In Python comments are represented with the hash symbol Anything after the hash symbol on a line is considered a comment and will not be executed Multiple assignment of variables can be done in Python For example sum flag d b 0 This assigns the value 0 to all four variables Another way to assign multiple values to multiple variables in a single line is sum flag d b 0 0 0 0 If you want to assign different values to the variables you can do sum flag d b 0 1 python 3 5 In Python statements do not end with a semicolon like in C Each statement is terminated by a new line If you want to represent multiple statements in a single line you can separate them with a semicolon


View Full Document

Anna GE 8151 - Python Programming - Data types, variables, identifiers (1)

Download Python Programming - Data types, variables, identifiers (1)
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Python Programming - Data types, variables, identifiers (1) and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Python Programming - Data types, variables, identifiers (1) 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?