You are on page 1of 12

Package/Metho Description Code Example

Comments Comments are ​ 1

lines of text
● # This is a comment
that are

ignored by the
Copied!
Python

interpreter

when

executing the

code
Variable Assigns a Syntax:

Assignment value to a

variable ​ 1

● variable_name = value

Copied!

Example:

​ 1

​ 2

● name="John" # assigning John to variable

name

● x = 5 # assigning 5 to variable x

Copied!

Data Types ● Example:

Integer

● Float ​ 1

● Boolean ​ 2

● String
​ 3
​ 4

​ 5

● x=7 # Integer Value

● y=12.4 # Float Value

● is_valid = True # Boolean Value

● is_valid = False # Boolean Value

● F_Name = "John" # String Value

Copied!

print() Prints the Example:

message or

variable inside ​ 1

`()` ​ 2

● print("Hello, world")

● print(a+b)

Copied!
Concatenation Combines Syntax:

(concatenates)

strings ​ 1

● concatenated_string = string1 + string2

Copied!

Example:

​ 1

● result = "Hello" + " John"

Copied!

len() Returns the Syntax:

length of a

string ​ 1

● len(string_name)

Copied!

Example:

​ 1
​ 2

● my_string="Hello"

● length = len(my_string)

Copied!

upper() Converts string Example:

to uppercase

​ 1

​ 2

● my_string="Hello"

● uppercase_text = my_string.upper()

Copied!

lower() Converts string Example:

to lowercase

​ 1

​ 2

● my_string="Hello"

● uppercase_text = my_string.lower()
Copied!

Slicing Extracts a Syntax:

portion of the

string ​ 1

● substring = string_name[start:end]

Copied!

Example:

​ 1

​ 2

● my_string="Hello"

● substring = my_string[0:5]

Copied!

Indexing Accesses Example:

character at a

specific index ​ 1

​ 2

● my_string="Hello"
● char = my_string[0]

Copied!

strip() Removes Example:

leading/trailing

whitespace ​ 1

​ 2

● my_string="Hello"

● trimmed = my_string.strip()

Copied!

replace() Replaces Example:

substrings

​ 1

​ 2

● my_string="Hello"

● new_text = my_string.replace("Hello", "Hi")

Copied!
split() Splits string Example:

into a list

based on a ​ 1

delimiter ​ 2

● my_string="Hello"

● split_text = my_string.split(",")

Copied!
Python ● Example:

Operators Additio

n (+): ​ 1

Adds ​ 2

two
​ 3
values
​ 4
together

. ​ 5

● Subtrac ​ 6

tion (-):
​ 7
Subtrac
​ 8
ts one

value ● x=9

from ● y=4

another.
● result_add= x + y # Addition
● Multipli
● result_sub= x - y # Subtraction
cation
● result_mul= x * y # Multiplication
(*):

Multipli ● result_div= x / y # Division

es two
● result_fdiv= x // y # Floor Division
values.
● result_mod= x % y # Modulo
● Division

(/):
Copied!
Divides
one

value

by

another,

returns

a float.

● Floor

Division

(//):

Divides

one

value

by

another,

returns

the

quotient

as an

integer.

● Modulo

(%):

Returns

the

remaind
er after

division

Author(s)
Pooja Patel

Contributor(s)
Malika Singla

Changelog

Date Version Changed by Change Description

2023-08-10 0.1 Pooja Patel Initial version created

You might also like