Lists
list()
constructor to make a List:
Lists
list()
constructor to make a List:Creating Comments in Python
Single Line Comment: Comments starts with a #
We can write comments at the beginning or at the end .
Variable Declaration
Rules for variable declaration
Data Types
Python Numeric Data Type
Int
Int, or integer, is a whole number, positive or negative, without decimals, of unlimited length.
Float, or "floating point number" is a number, positive or negative, containing one or more decimals.
Float can also be scientific numbers with an "e" to indicate the power of 10
Complex numbers are written with a "j" as the imaginary part:
Boolean Type
If an expression is True
or False
.
The bool()
function allows you to evaluate any value, and give you True or False
in return,
Any string is True
, except empty strings.
Any number is True
, except 0
.
Any list, tuple, set, and dictionary are True
, except empty ones.
The following with return False
Note : Functions can return Boolean values as well.
Example
String Data Type
We can use single quotation marks, or double quotation marks.
'uday' or "uday".
What is Python?
Python is a popular programming language. It was created by Guido van Rossum, and released in 1991.
It is used for:
Web Development (server-side),
Software development,
Mathematics,
System scripting.
To check the Python version of the editor, you can find it by importing the sys
module:
Intro to Python - Syntax
Indentation: Indentation refers to the spaces at the beginning of a code line.
We should be using either space or tab while using functions, loops and conditional statements.
In other programming languages we use the Curley braces, which indicates that is a block of code. Where as in the Python we use space or tab
If the indentation is skip, we will get Error
Variables:
Python variables doesn’t need to be embedded with datatype at beginning as python has that capacity to capture the datatype based on the value assigned.
Example: a=10
In above example a is variable, python will assign this variable as int datatype. A is the variable.
Assigning multiple values at the same time.
x,y,z=1,2,3 #This assigns x=1, y=2 and z=3
Variables do not need to be declared with any particular type, and can even change type after they have been set.
Lists It is used to store Collection of data. Lists are created using square brackets: List Items Order cannot be changed. It can have dup...