Python Chapter#9: Python Dictionary

Ankur Kulhari

Items of dictionaries are enclosed by curly braces ({}) Consist of key-value pairs A dictionary key can be any Python data type,(usually numbers or strings) Values, can be any Python object. Values can be assigned and accessed using square braces ([]) Ex: OUTPUT: Hello 123 {‘Employee_code’: 6103467, ‘dept’: ‘CSE’, ‘name’: ‘jonny’} dict_keys([‘Employee_code’, ‘dept’, ‘name’]) dict_values([6103467, ‘CSE’, ‘jonny’]) Python Dictionary Functions …

Python Chapter#8: Python Lists

Ankur Kulhari

Python Lists A list in python is a compound data type which can store multiple elements. Items of a list are enclosed within square brackets ([]) Items are separated by commas The items of a list can be of different data type. Ex: l1 = [1,2,”a”,2.3,3j] Slice operator ([ ] and [:] ) can be used to access elements in …

Python Chapter#7: Python Strings

Ankur Kulhari

Python Strings In Python character type variables are not defined; they are treated as strings of length one. Strings in Python are set of characters enclosed in the pair of quotation marks (either single or double quotes). Slice operator ([ ] and [:] ) can be used to take subset of string Indexes start at 0 Concatenation operator: plus (+) …

Pyhton Chapter#6: Numbers

Ankur Kulhari

In python numeric data types store numeric values. Number objects are created when a value is assigned to them. Ex: num1 = 5 num2 = 10 Four different numerical types are supported in python: int (signed integers) long (long integers, they can also be represented in octal and hexadecimal) float (decimal/real values) complex (complex numbers) Mathematical Functions Python includes following …

Python Chapter#5: Loops

Ankur Kulhari

To execute statement/s multiple times, loops are used. Python loops: Python While Loop Python For Loop Python Nested Loops While Loop Condition is tested before executing the loop body. The condition may be any expression, and any non-zero value is considered as true The loop iterates while the condition is true When the condition becomes false, program control passes to …

Python Chapter#4: If-else

Ankur Kulhari

In Python: Any non-zero and non-null values are considered as TRUE, and Zero or NULL are considered as FALSE value Python has 3 types of decision/if-else statements as: Statement Description Syntax if An if statement consists of a boolean expression followed by one or more statements. Ex:Boolean expression: (x>y) if expression: statement(s) if…else An if statement can be followed by …

Python Chapter#3: Basic Python Operators

Ankur Kulhari

An operator is a construct which performs some operation: arithmetic or logical, on operands. Operators in Python Python has following operators: Arithmetic Operators Comparison/Relational Operators Assignment Operators Logical Operators Bitwise Operators Membership Operators Identity Operators Python Arithmetic Operators Operator Description Example [x=33, y=10] Addition (+) Binary addition operator which adds both operands. x+y=33+10=43 Subtraction (-) Binary operator which subtracts right …

Python Chapter#2: Variable Types

Ankur Kulhari

A variable is associated with pair of a storage location and associated symbolic name (an identifier), i.e. [location,identifier]. Location is used by system and identifier is used by user/programmer to access the variable When a variable is created, some space in memory is reserved Data type of a variable decides, the amount of reserved memory and what can be stored …

Python Chapter#1: Getting Started with basic syntax

Ankur Kulhari

In python there are two modes available to program as Matlab: Interactive Mode Programming Script Mode Programming Now let’s see how to program in these modes: Interactive Mode Programming Python instructions can be directly executed from the python prompt. Ex: Ex: Ex: Script Mode Programming Similar to m file in matlab, python also provides facility to write program in a …