0% found this document useful (0 votes)
5 views10 pages

Python Basics: Data Types & Syntax

The document provides an overview of Python programming, highlighting its features such as being interpreted, object-oriented, and easy to learn. It covers installation, variable creation, data types, and basic operations including lists and tuples. Additionally, it discusses string manipulation, input/output functions, and the importance of indentation in Python code.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views10 pages

Python Basics: Data Types & Syntax

The document provides an overview of Python programming, highlighting its features such as being interpreted, object-oriented, and easy to learn. It covers installation, variable creation, data types, and basic operations including lists and tuples. Additionally, it discusses string manipulation, input/output functions, and the importance of indentation in Python code.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

#Father - Guido Van Rossum - 1991

#Python is:

#Interpreted

#Functional/Procedural

#Object Oriented

#High Level

#General Purpose language.

#Why:

#Easy to learn

#Performance

#Rapid Development

#Dynamically Typed

#Community

#Simple syntax

#Fast built libraries/Modules

#Portable--works on different platforms

#Third Party Libraries--batteries included

#Mainly Used:

#Data Science

#AI/ML

#Web Development Framework

#Application Development

#Python Installation:

#Pycharm Community Addition

#Integrated Development Environment

--------------------------------------------------------------

#Comments- # Single line


# """ """ --multiple lines

# Hope Foundation

""" My name is Sowbhagya

I work for Hope foundation"""

#Indentation --Spaces at the start of the code, indicates a block of code.

#Creating Variable

a=5

b = "Hope"

print(a,b)

#Variables -- Stores a single value

#Identifiers-- a variable with a name

#A variable name must start with a letter or the underscore character

#A variable name cannot start with a number

#A variable name can only contain alpha-numeric characters and underscores (A-z,0-9, and _)

#Variable names are case sensitive (Age, age)

#A variable name cannot be any of the python keywords.

#_userID -- Private

#__userID -- very very private

#__init__ --Special/magic function

#Variable Names(descriptive names)

#Camel Case - myVariableName = "Hope"

#Pascal Case -- MyVariableName = "Hope"

#SnakeCase -- my_variable_name = "Hope"

#-----------------------------------------------------
#input() function --Takes input from the User in the form of string

#print() function -- Outputs the result on the terminal

#-----------------------------------------------------

#Datatypes:

#None Type

#Text Type -- str

#Numeric Types -- int float Complex

#Sequences -- list, tuple and range

#Sets -- duplicate

#Mapping -- Dict

#Boolean Type ---bool

#Binary Type – bytes

#None Type

a = None

print(a)

#Numeric Types

#int

#float

#complex

--------------------------------------------------------------------

#Type casting

x=33.5

h = int(x)

print(h)

i= float("22.5")

print(i)

print(type(i))
print(hex(10))

print(oct(10))

o/p -- 0xa, o012

-------------------------------------------------------------------

#Boolean Type

#Carry 2 values: True or False

#Conditional/Looping

print(9>8)

#o/p -- True

--------------------------------------------------------------

#Text Type:

#String

#Create a String Data --new file

s = (" Hope foundation ")

print(s)

s1 = """ You are the creator of your own destiny """

print(s1)

#Strings are Immutable: Character of a sting cannot be changed once created.

s[0] = 'D'

print(s)

#o/p -Error
#Indexing --- Reaching out to a particular character in the string.

#Index value always starts from 0 and goes till(len-1)

print(s[0])

#Repetition:

print(s*2)

#length function

print(len(s))

#slicing

print(s[0:5])

print(s[0:])

print(s[:8])

print(s[-3:-1])

#-1 represents the last element

#passing a step value:

print(s[0:9:2])

# default step value is 1

print(s[15: :-1])

#reverses a string

print(s[::-1])

#String functions:

#strips out the spaces at the start and end

print([Link]())

print([Link]())

print([Link]())

#find a substring
print([Link]("ope"))

print([Link]("o"))

print([Link]("Hope","Great")

#string methods

print([Link]())

print([Link]())

print([Link]())

#Formatting

name = "Sowbhagya"

country = "India"

print(f"{name} is from {country}")

print("{} is from {}".format(name,country))

----------------------------------------------------------

Sequences

----------------------------------------------------------

#List Datatype -- stores multiple values in an ordered index

#Mutable,Ordered, duplicates are allowed

#we can store duplicates in list --- number of copies of an element

#Empty list

lst = []

print(lst)

#creating a list

lst = [10,20,"Sowbhagya",-10,30.5]

print(lst)
#we can perform Indexing, Slicing, Repetition and find length

print(lst[3])

print(lst[3:5])

print(lst*4)

print(len(lst))

#methods to add and remove elements from list

#Adds item(40) to the end of the list

[Link](40)

print(lst)

#Inserts item(99) at the index position mentioned(3)

[Link](3,99)

print(lst)

#Removes item(Sowbhagya) from the list

[Link]("Sowbhagya")

print(lst)

#Adds more than 1 item at the end of the list

[Link]([20,21])

print(lst)

#Reverse all the items in the list

[Link]()

print(lst)

#list Operations: len(), min(), max()

len(lst)
max(lst)

min(lst)

del(lst[1])

---------------------------------------------

#Tuple () ,

#Once we create a tuple we cannot change

#Immutable

#ordered

#Duplicates

#creating a tuple

tp1 = (20,30,40,20,"xyz")

tp1[2] = 123

print(tp1)

tp2 = (20,)

print(type(tp2))

print(tp1*3)

print([Link](20))

print([Link]("xyz))

#always remember that we can use the functions on tuple that will not modify the elements of the
tuple

min()

max()

count()
#list to tuple:

lst =[67,34,"xyz"]

tup1 = tuple(lst)

print(tup1)

#Operations: min(), max() and count()

lst =[67,34,67]

tup1 = tuple(lst)

print(tup1)

a =min(tup1)

print(a)

# When using string as elements, tuple considers the length of the string to evaluate

Tuple = ("Hope", "Foundation", "Bajaj", "Finserv")

res = min(Tuple)

print('Minimum of Tuple is', res)

b = max(tup1)

print(b)

#count() --counts the number of occurrences of the element mentioned within the brackets

c =[Link](67)

print(c)

----------------------------------------------------------

You might also like