Python
Gagan Puri
[Link]/in/puri-gagan
higaganpuri@[Link]
Contents
●
Introduction
●
IDE
●
pip
●
Environment Management
●
Tokens
●
Identifiers
●
Data Types
●
Type Cast
●
Operators
●
Next Class
Python
●
High-level, interpreted, general-purpose programming language
●
Created by Guido van Rossum and released in 1991
●
3.13
●
Python uses indentation (whitespace) to define blocks of code, rather than braces {}
IDE
●
Pycharm
●
VS Code
●
Jupyter Notebook
pip
●
package installer for Python
●
Install, update, and manage Python libraries (also called packages or modules)
●
From the Python Package Index (PyPI) and other repositories
Environments
●
Practice of creating isolated environments for Python projects
●
Used to ensure that the libraries and dependencies used for one project don't conflict with those in
another project
●
Useful when working on multiple projects that require different versions of libraries or Python
●
Easier Deployment
Tools to manage python environments
●
venv (Built-in Tool)
●
python3 -m venv myenv
●
source myenv/bin/activate
●
myenv\Scripts\activate
●
Virtualenv
●
pip install virtualenv
●
virtualenv myenv
●
Conda
Anaconda / Mini Conda Environments
Managing Environments
Managing Environments
Tokens
●
Tokens are the smallest units in a Python program. They are the building blocks of any program
●
Keywords: Reserved words that have a special meaning in Python. Examples: if, for, while, class, def,
try, etc
●
print([Link])
●
Identifiers: Names given to variables, functions, classes, etc
●
Literals: Fixed values that appear directly in code. Example: 5, "Hello"
●
Operators: Symbols used to perform operations on variables and values. Example: +, -, *, ==
●
Separators: Symbols used to separate statements or blocks of code. Example: :, ,, ;, (), {}, []
●
Comments: Non-executing text used to explain the code. Single-line comments begin with #, while
multi-line comments are written between “” “” or '''
Indentifiers
●
Identifier is a name used to identify a variable, function, class, module, or other object
●
It must begin with a letter (A-Z or a-z) or an underscore (_).
●
It can contain digits (0-9) after the first letter
●
Python identifiers are case-sensitive (e.g., var, Var, VAR are different)
●
Keywords cannot be used as identifiers
●
Identifiers can’t contain only digits
●
No limit on the length of the identifier name in python
Data Types
●
Numbers:
●
int: Integer (e.g., 5, -3).
●
float: Floating-point numbers (e.g., 3.14, -0.001).
●
complex: Complex numbers (e.g., 3+5j).
●
Strings: A sequence of characters (e.g., "Hello World", 'Python').
●
Strings can be enclosed in single quotes (') or double quotes (").
●
Lists: Ordered, mutable collection of elements (e.g., [1, 2, 3, 'a', 4.5]).
●
Tuples: Ordered, immutable collection (e.g., (1, 2, 3)).
●
Dictionaries: Unordered collection of key-value pairs (e.g., {'name': 'Alice', 'age': 25}).
●
Sets: Unordered collection of unique elements (e.g., {1, 2, 3, 4}).
●
Booleans: Represents True or False
Type Casting
●
Conversion between different data types using built-in functions
●
int(): Converts to an integer.
●
float(): Converts to a floating-point number.
●
str(): Converts to a string.
●
list(), tuple(), set(), dict(): Convert between different collection types
Operators
●
Operators are symbols used to perform operations on variables or values
●
Arithmetic Operators: +, -, *, /, // (floor division), % (modulus), ** (exponentiation).
●
Comparison Operators: ==, !=, >, <, >=, <=.
●
Logical Operators: and, or, not.
●
Assignment Operators: =, +=, -=, *=, /=, //=, %=, **=.
●
Bitwise Operators: &, |, ^, ~, <<, >>.
●
Membership Operators: in, not in.
●
Identity Operators: is, is not