0% found this document useful (0 votes)
2 views

Python Basics

The document provides an overview of Python basics, covering data types such as numbers, strings, and booleans, as well as the concept of variables and their rules. It also explains various expressions, including arithmetic, relational, and logical expressions, along with string operations like indexing, slicing, and formatting. Additionally, it details methods for manipulating strings, such as counting, replacing, and splitting.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Python Basics

The document provides an overview of Python basics, covering data types such as numbers, strings, and booleans, as well as the concept of variables and their rules. It also explains various expressions, including arithmetic, relational, and logical expressions, along with string operations like indexing, slicing, and formatting. Additionally, it details methods for manipulating strings, such as counting, replacing, and splitting.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

Python Basics

Python Basics
Data types

Variables

Expression

String operations
Data types
Data types
Numbers

Strings

Boolean
Numbers

10

11.2

2 + 5j
Number type conversion

int(5.32) 5

float(11) 11.0

complex(10) 10 + 0j
String

"40"

'Hello'

"Hello"
Boolean
Variables
Variables

Variables are containers for


storing data values
variables

To create a variable, you simply need

to assign a value to a name using the

assignment operator (=)


Rules for python variable

variable names in Python have to start with a letter or an underscore

They cannot start with a number

They can't contain any special characters other than an underscore

Variable names are case-sensitive (age, Age and AGE are three different variables)
Expressions
Arithmetic expression
Relational expression
Assignment expression
Logical expression

or
and
not
Identity expression
Membrership expression
String operations
Length of a string
Indexing
string slicing
string concatenation

"Hello" "world" "Hello world"


string format
we cannot combine strings and
"His age is" 20 numbers

But we can combine strings


and numbers by using the
format method

placeholders should be created


with {}
Find the index

This will return the

index position of the

specified string
Count

This will return the

number of occurances

of specified string
Capitalize

The first character is converted

to upper case, and the rest are

converted to lower case


Upper

It converts all characters

present in the string into

upper case
Lower

It converts all characters

present in the string into

lower case
Replace

This method replaces a

specified string with another

specified string.
Replace

The count can also be

mentioned to specify how

many occurrences of the

old value you want to

replace.
Split

This will split each word into

separate strings
Split

You can also

specify where to

split
Center

This method will center

allign the string based on

the specified length


Find

It finds the index of

first occurance of

specified string
Find

You can also metion

between the starting

and ending index


rFind

rfind is similar to find,

but rfind searches

from right side


Strip

This will remove the

specified string in

starting and ending

position

You might also like