Anna CS 8791 - UNIT II: DATA TYPES, EXPRESSIONS, STATEMENTS

Unformatted text preview:

UNIT II DATA TYPES EXPRESSIONS STATEMENTS Python Interpreter and Interactive Mode Python is an interpreted language which means that the code is executed by an interpreter line by line The Python interpreter is a program that reads and executes Python code It can be used in interactive mode where you can enter Python commands and see the results immediately Debugging Debugging is the process of identifying and fixing errors bugs in a program Python provides various debugging tools and techniques such as print statements debuggers and exception handling Values and Types In Python every value has a type associated with it The basic data types in Python are 1 int integers Whole numbers e g 42 7 2 float floating point numbers Numbers with decimal points e g 3 14 0 7 3 bool booleans Logical values either True or False 4 str strings Sequences of characters e g hello world 5 list lists Ordered collections of values e g 1 2 3 a b c Variables Variables are used to store and manipulate data in a program In Python you can assign values to variables using the assignment operator Expressions and Statements An expression is a combination of values variables operators and function calls that evaluates to a value A statement is a complete instruction that performs an action such as assigning a value to a variable or executing a function Tuple Assignment Python allows you to assign multiple values to multiple variables in a single statement using tuple assignment Example x y 3 4 Precedence of Operators Python follows a specific order of operations when evaluating expressions This order is determined by the precedence of operators which defines the order in which operations are performed Comments Comments are human readable annotations in the code that are ignored by the Python interpreter They are used to explain the code or provide additional information In Python single line comments start with and multi line comments are enclosed between triple quotes or Illustrative Programs 1 Exchange the values of two variables x y y x 2 Circulate the values of n variables a b c c a b 3 Distance between two points distance math sqrt x2 x1 2 y2 y1 2


View Full Document

Anna CS 8791 - UNIT II: DATA TYPES, EXPRESSIONS, STATEMENTS

Download UNIT II: DATA TYPES, EXPRESSIONS, STATEMENTS
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 UNIT II: DATA TYPES, EXPRESSIONS, STATEMENTS 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 UNIT II: DATA TYPES, EXPRESSIONS, STATEMENTS 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?