1/171
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
Python
interpreted programming language known for its simplicity, readability, and versatility
supports multiple programming paradigms, including procedural, object-oriented, and functional programming, making it adaptable to different coding styles.
Python is
readable
dynamically typed
extensive standard library
cross plat
versatile
interpreted nature
Programming Paradigm
a fundamental style or approach to programming that dictates how tasks should be structured and executed in each programming language. It encompasses principles, concepts, and patterns that guide the design and organization of code.
imperative/procedural programming
focuses on describing a sequence of steps to perform a task, procedures or routines.
object-oriented programming (OOP)
organizes code around objects, which encapsulate data and behavior
functional programming
emphasizes the use of functions and immutable data for computation
declarative programming
describes what the program should accomplish without specifying how to achieve it
event-driven programming
reacts to events and user actions, triggering corresponding functions
logic programming
defines a set of logical conditions and lets the system deduce solutions
indentation
defines blocks of code. crucial for structure and nesting of code blocks
(4 spaces)
comments
#
ignored by interpreter, for humans
Variable
used to store data, created by assigning a value to a name
Data Types
integers, floats, strings, lists, tuples, dictionaries
conditional statements
if, else, elif (else if)
Classes
(also objects) fundamental to object oriented programming in python.
print ()
used to output data to the console
print ("hello")
functions
defined using def
def greet(name):
print ("Hello, name")
run python script in cmd prompt
python script.py
How to run phython script in Python3
python3 script.py
Integrated Development Environments (IDEs)
provide a more user-friendly environment for coding, debugging, and running Python scripts
Markdown file
simple format used frequently to add styled text, images, code snippets and more to coding repos serving as documentation
human readable
.md
markdown file
Consistent Indentation
All statements within the same block must be indented by the same number of spaces.
input()
function, storing user entered info as strings
output()
functions, allowing the presentation of results or messages
format()
method, enhances output formatting by embedding variables in strings
file I/O
through the open() functions enabling reading from and writing to external files.
len ()
determines the length of a sequence
type ()
returns the type of an object
int (), float (), str ()
converts values to integers, floats, or strings
max (), min()
returns the max or min value from a sequences
sum ()
finds the sum of elements in a sequence
abs ()
returns the absolute value of a number
range ()
generates a sequence of numbers
sorted ()
returns a sorted list from an iterable
any (), all()
checks if any or all elemebts in an interable are true
map (), filter ()
applies a function to elements or filters elements based on a functions
open (), read (), write ()
handles file I/O operations
dir ()
lists the names in the current scope or attributes of an object
help ()
provides help info about an object or Python
interactive shell
enables the execution of python code interactively, providing tools for creating, opening, and saving projects.
version control integration
supports integration with version control sys like Git for effcient collaboration and code versioning
code navigation
facilitates easy navigation through large codebases by offering features such as code folding, code outlining, and quick navigation to definitions.
integrated documentation
provides access to documentation for Python libraries and modules directly within the IDE
code profiling
Allows developers to analyze code performance and identify areas for optimization
Problem solving process
analyze problem
develop algo
write code
test and debug
python is dynamically typed
variable types in python are determined at runtime
Purpose of code editor in python IDE
provide a text editor offering syntax highlighting, code completion, and indentation.
Python variables
serving as placeholders to store and manage data. In Python, you don't need to explicitly declare a variable's data type; it dynamically infers it based on the assigned value.
Symbolic Names
refer to names or identifiers that represent values, objects, or entities.
variable name rules
number, letters, _
start with letter or _
cannot be a python keyword
assign multiple variables
x, y, z = "one", "two", "three"
assigning the same value multiple variables
hi = hello = hey = "greeting"
printing multiple variables with , and +
+ will combine strings, and also numbers but not together
, will combine strings and numbers together.
inside a function
means the code is part of a specific function block. Variables defined inside the function have local scope, and the function executes when called.
outside a function
means the code is not part of any specific function block. Variables defined outside functions generally have a global scope and can be accessed throughout the program
function (local)
not accessible outside, promoting encapsulation.
Global Variables
declared outside of functions and can be accessed from any part of the program
core data types
integers, floats, strings
Lists and Tuples
facilitate the organization of multiple elements
dictionaires
enable key value pair storage.
str:
string
int:
integer
float:
floating-point type
boolean
true or falseu
is_true=true
is_false=false
list
ordered, mutalble sequence
[ ]
tuple
ordered, immutable sequence
( )
set:
unordered, mutable collection of unique elements
frozenset:
unchangeable set
dict:
dictionary, an unordered collection of key-pair values
int_num = int(float_num)
converting something to integer, int
same for x = float(y)
x = round(y)
x=abs(y) - absoluite value
You can create multiple strings with
three quotes
Repitition (*)
repeat a string
concatenation (+)
combine two strings
Indexing ([])
accessing individual characters by position. First pos is 0.
(f-strings)
stands for format. Replaces the name of any variable in braces with its value.
\n
\t
new line
new tab
string slicing
refers to the technique of extracting a portion of a string by specifying a range of indices
start, stop, and step
string [start:stop:step]
start is where slicing begins
-if not provided default to beginning of string
stop is where slicing ends
- if not provided default to end of string
step or stride between characters
- if not provided default to 1
immutable
cannot be changed
mutable
can be changed
you can modify strings with
replace ()
upper ()
lower ()
count ()
counts the occurrences of a substring in the given string
strip ()
removes leading and trailing whitespaces
lstrip ()
removes leading white spaces
rstrip ()
removes trailing whitepsaces
+=
shorthand for concatenation and assignment
greeting = "Hello "
greeting =+ "Python!"
print (greeting)
Hello Python
join ()
combine strings from an iterable (list)
positional arguments
arguments that are passed to a function or method in a specific order.
named arguments
keyword arguments, passed to a function or method by explicitly stating the name of the parameter and its value.
assignment operators
=, +=, -=, =, /=, %=, //=, *=
membership operators
in, not in
identity operators
is, is not
modulus %
returns the remainder
floor division //
performs division and rounds down to the nearest whole number.
bitwise shift << >>
lower than arthimetic operations
Exponentiation **
next highest
bitwise AND &
lower than shifts
bitwise XOR ^
lower than AND