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

Python Notes Typed

This document discusses Python data types including numbers, strings, Booleans, and variables. It covers the main number types (integers, floats, complex numbers), variable naming conventions, and string concepts like indexing, accessing characters, and reversing indexing. Python supports a variety of number types and operations as well as strings, Booleans, and variables to store and manipulate data.

Uploaded by

Taashi Agarwal
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

Python Notes Typed

This document discusses Python data types including numbers, strings, Booleans, and variables. It covers the main number types (integers, floats, complex numbers), variable naming conventions, and string concepts like indexing, accessing characters, and reversing indexing. Python supports a variety of number types and operations as well as strings, Booleans, and variables to store and manipulate data.

Uploaded by

Taashi Agarwal
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

educative.

io
password-taashi@1511

Python is a high level language.


To print the coding is
print ("Hello World")
print (100,50,30)
THE DATA TYPE - of an item defines the type ahd range of values that item can have.
The language provides three main data types:
.Numbers
.Strings
.Booleans

VARIABLES
A variable is simply a name to which a value can be assigned.
Variables allow us to give meaningful names to data.
The simplest way to assign a value to a variable is through the = operator.

Variable = Value or expression

Yariables are mutable. Hence, the value of variable can always be updated or
replaced.

NAMING CONVENTION
There are certain rules we have to follow when picking the name for a variable:

The name can start with an upper or lower case alphabet.

A number can appear in the name, but not at the beginning.

The _ character can appear anywhere in the name.

Spaces are not allowed. Instead, we must use snake_case to make variable names
readable.

The name of the variable should be something meaningful that describes the value it
holds, instead of being random characters.

Numbers
This lesson provides an in-depth discussion about numbers in Python.

Python is one of the most powerful languages when it comes to manipulating


numerical data.

It is equipped with support for several types of numbers, along with utilities for
performing computations on them.

There are three main types of numbers in Python:


.Integers
.Floating-point numbers
.Complex numbers

svg viewer
Integers
The integer data type is comprised of all the positive and negative whole numbers.
The amount of memory an integer occupies depends on its value. For example, 0 will
take up 24 bytes whereas 1 would occupy 28 bytes.

Here are some examples of integers:

FLOATING POINT

Floating-point numbers, or floats, refer to positive and negative decimal numbers.

Python allows us to create decimals up to a very high decimal place.

This ensures accurate computations for precise values.

A float occupies 24 bytes of memory.


In Python, 5 is considered to be an integer while 5.0 is a float.

COMPLEX NUMBERS
Python also supports complex numbers, or numbers made up of a real and an imaginary
part.

Just like the print() statement is used to print values, complex() is used to
create complex numbers.

It requires two values. The first one will be the real part of the complex number,
while the second value will be the imaginary part.

Here’s the template for making a complex number:

complex(real, imaginary)

A complex number usually takes up 32 bytes of memory.

BOOLEAN
The Boolean (also known as bool) data type allows us to choose between two values:
true and false.
In Python, we can simply use True or False to represent a bool:
A Boolean is used to determine whether the logic of an expression or a comparison
is correct. It plays a huge role in data comparisons.

STRINGS
A string is a collection of characters closed within single or double quotation
marks.

A string can also contain a single character or be entirely empty.

The length of a string can be found using the len statement. This length indicates
the number of characters in the string:

INDEXING
In a string, every character is given a numerical index based on its position.

A string in Python is indexed from 0 to n-1 where n is its length. This means that
the index of the first character in a string is 0.

ACCESSING CHARACTERS
Each character in a string can be accessed using its index. The index must be
closed within square brackets, [], and appended to the string.

REVERSING INDEXING
We can also change our indexing convention by using negative indices.

Negative indices start from the opposite end of the string. Hence, the -1 index
corresponds to the last character:

You might also like