Effective Date 01.06.2024 Page No.
Page 1 of 6
VIVEKANANDHA COLLEGE OF ARTS AND SCIENCES FOR WOMEN
(Autonomous)
Course Material
[Link] Computer
Department Computer Science Programme
Science
MACHINE LEARNING USING
Course Title Course Code 24U5CSC05
PYTHON
Semester &
Class & Section III BSC CS A V Sem, 2024-25
Academic Year
ASSISTANT
Handling Staff J. REVATHI Designation
PROFESSOR
Staff Incharge HoD Principal
VIVEKANANDHA COLLEGE OF ARTS AND SCIENCES FOR WOMEN
(Autonomous)
Effective Date 01.06.2024 Page No. Page 2 of 6
PROGRAMMING IN PYTHON
Programscan bewrittenin twoways:
Interactivemode
Scriptmode
1. The Interactive mode allows us to write codes in Python command prompt(>>>). The prompt (>>>)
indicates that Interpreter is ready to
[Link].
2. In script mode programs can be written and stored as separate file with
[Link].
The version 3.x of Python IDLE (Integrated Development
LearningEnvironment)[Link]
[Link].
VARIABLE
Avariableassociatesanamewithavalue,makingiteasytorememberandusethe value laterinaprogram.
An Identifier is a name used to identify a variable, function, class, moduleorobject.
Rules:
Somenames,suchasif,def,andimport,arereservedforotherpurposesand thuscannot
beusedforvariable names.
Ingeneral,avariablenamemustbeginwitheitheraletteroranunderscore(_).
Andcancontainanynumberofletters,digits,orotherunderscores.
Pythonvariablenamesarecasesensitive.
Identifiersmaycontaindigits(0..9)
Identifiersmustnotbeapythonkeyword.
Python does not allow punctuation character such as %,$, @ etc., withinidentifiers.
Effective Date 01.06.2024 Page No. Page 3 of 6
VIVEKANANDHA COLLEGE OF ARTS AND SCIENCES FOR WOMEN
(Autonomous)
Pythonprogrammerstypicallyuselowercaselettersforvariablenames,butinthecaseofvariablenamest
hatconsistofmorethanoneword,thenameEx:interestRatecanbeused,the2nd wordstartswithuppercas
e,Easyuse.
Programmers use all uppercase letters for the names of variables thatcontain
valuesthattheprogram never changes.
[Link]:TAX_RATEandSTAN
DARD_DEDUCTION.
DATATYPE
In programming, a data type consists of a set of values and a set of operations that can be performed on
those values. All data values in Python are objects and each object or value has type.
Python has Built-in or Fundamental data types such as Number, String, Boolean, tuples, lists, sets and
dictionaries etc.
Example literals of several Python data types.
TYPE OF DATA PYTHON TYPE EXAMPLE LITERALS
NAME
Integers int -1, 0, 1, 2
Real numbers float -0.55, .3333, 3.14, 6.0
Character strings str “Hi”, “”, 'A', '66'
Number Data type
The built-in number objects in Python supports integers, floating point numbers and complex numbers.
Integer Data can be decimal, octal or hexadecimal
Example:
102, 4567, 567 # Decimal integers 0o102, 0o876, 0o432 # Octal integers 0X102, 0X876, 0X432
# Hexadecimal integers
34L, 523L # Long decimal integers
A Floating Point Data is represented by a sequence of decimal digits that includes a decimal point. An
Exponent data contains decimal digit part, decimal point, exponent part followed by one or more digits.
VIVEKANANDHA COLLEGE OF ARTS AND SCIENCES FOR WOMEN
(Autonomous)
Effective Date 01.06.2024 Page No. Page 4 of 6
Example :
123.34, 456.23, 156.23 # Floating point data 12.E04, 24.e04 # Exponent data
Complex number is made up of two floating point values, one each for the real and imaginary parts.
Boolean Data type
A Boolean data can have any of the two values: True or False.
Example :
Bool_var1=True Bool_var2=False
String Data type
String data can be enclosed in single quotes or double quotes or triple quotes.
Example :
Char_data = ‘A’
String_data= "Computer Science"
Multiline_data= ”””String data can be enclosed in single quotes or double quotes or triple quotes.”””
Tuple Data type
It is a type of data structure that is very similar to lists.
Tuples are immutable, meaning they cannot be changed once they are created.
This makes them ideal for storing data that should not be modified, such as database records.
Effective Date 01.06.2024 Page No. Page 5 of 6
VIVEKANANDHA COLLEGE OF ARTS AND SCIENCES FOR WOMEN
(Autonomous)
List Data type
Lists are used to store multiple items in a single variable.
Lists are one of 4 built-in data types in Python
Lists are created using square brackets
Example Python program
# Creating a List
List = []
print("Blank List: ")
print(List)
# Creating a List of numbers
List = [10, 20, 14]
print("\nList of numbers: ")
print(List)
# Creating a List of strings and accessing
# using index
List = ["Geeks", "For", "Geeks"]
print("\nList Items: ")
print(List[0])
print(List[2])
Output
Blank List:
[]
List of numbers:
[10, 20, 14]
VIVEKANANDHA COLLEGE OF ARTS AND SCIENCES FOR WOMEN
(Autonomous)
Effective Date 01.06.2024 Page No. Page 6 of 6
List Items:
Geeks
Geeks
SET Data type
Sets are used to store multiple items in a single variable.
Set is one of 4 built-in data types in Python
A set is a collection which is unordered, unchangeable, and unindexed.
Set items are unchangeable, but you can remove items and add new items