Posts

Lists in Python

Image
 Lists • In Python lists are used to store multiple items in a single variable. • Lists are initialised within square brackets [ ]. • Lists are ordered,mutable (i.e can be changed) and allow duplicate values. Syntax to create list :                 mylist = [ 1,2,3, 'A','B' ] • We can also access elements in list by indexing :        In :  print (mylist[0])      Out :  1 • We can also change item values in list as :        In :  mylist[ 1 ] = ' C '         print (mylist)       Out :  [ 1,'C',3,'A','B' ] Common Functions performed on Lists are as follows : Examples on above functions are as follows :

Strings in Python

Image
 STRINGS Strings are sequence of characters enclosed within single quotes ( '   ' ) or double quotes ("   "). We can display strings with print function.   F or example:   Input:  mystr= "Hello World!"                       print( mystr )                                            OR                                  Input: print( "Hello World!" )                                            Output:    Hello World! In Python we can write multiline strings using triple quotes  ( ' ' '      ' ' '  ). For example :  Input:     mystr = ''' ...

Python Data Types

Image
 PYTHON NUMBERS Python numbers are combination of Integers , Floating point numbers and Complex numbers. The Numbers are defined as int, float and complex class in python. We use type() function to check whether which class a variable belongs to. Taking Input from user in Python : In Python we can take input from user by using 'input' keyword. Refer Following example for better understanding.

Operators in Python

Image
 OPERATORS An operator in a programming language is a symbol that tells the compiler or interpreter to perform specific mathematical, relational or logical operation and produce final result. Types of Operators : 1) Arithmetic Operators : Addition Operator : ' + ' Subtraction Operator : ' - '  Division Operator : ' / ' Multiplication Operator : ' * '      Following are examples of Arithmetic Operators 2) Relational Operators : Greater than : ' > ' Less than : ' < ' Equals : ' == ' Greater than Equal to : ' >= ' Less than Equal to : ' <= ' Not Equal to : ' != '          Following is the example of Relational Operators : 3) Logical Operators : And Operator : ' & '  (  It returns TRUE if both the operands are True ) Or Operator : ' | '    (  It returns TRUE if either of the operand is True ) Following is the example of Logical Operators :   In Python w...

Variables in Python.

Image
 Variables Variables are temporary Storage spaces. In Python we can always reassign a variable. Python uses dynamic typing that means it can reassign variable name to different data types. Variable assignment in Python: note : Following code is executed in Jupiter notebook. note : To run particular cell in Jupiter Notebook press SHIIFT + ENTER. note : We can check type of a variable using type keyword in Python. We can assign variable in python as follows: syntax:   var_name = value In above example student variable is assigned to two different data types.

Introduction to Python Programming

Image
Python is a popular programming language. It was created by Guido van Rossum , and released in 1991. WHY PYTHON: 1) Python works on different platforms (Windows, Mac, Linux, Raspberry etc). 2)  Python has a simple syntax . 3)  Python has syntax that allows developers to write programs with fewer lines. 4)  Python runs on an interpreter system, meaning that code can be executed as soon as it is written. FIRST PROGRAM IN PYHTON: note : Python programs need to be saved with ".py" extension. SIMPLE PROGRAM TO PRINT HELLO WORLD! print("Hello World!") note : If using python on command prompt use syntax "python hello.py " to run the program. Output: Hello World! This was a small introduction to Python language from my side.