SlideShare a Scribd company logo
CODING WITH
PYTHON
Part one
Printing string, Functions, object &
method, Converting between types,
adding comments and Variables
WHICH PROGRAM TO USE?
• I have used Jupyter notebook from
Anaconda navigator.
• I find it easy to use and user friendly.
• It needs Mozilla firefox to be installed
• But it takes a lot of time to download and
installed (some 15 to 25 minutes based on
the speed of your PC) but once installed it
is quick to use.
THE INTERFACE WILL BE AS FOLLOWS
I WILL NOT EXPLAINED HOW TO INSTALL
THIS SOFTWARE YOU CAN GET A
DEMONSTRATION ON YOUTUBE
LIST OF ALL ARITHMETIC OPERATIONS SUPPORTED BY
PYTHON.TRYTHE FOLLOWING MEANING OUTPUT
2 + 3 * 6 20
(2 + 3) * 6 30
2 ** 8 256
23 // 7 Integer division (fractional part ignored) 3
23%7 Modulo (remainder left after division) 2
(5 - 1) * ((7 + 1) / (3 - 1)) 16.0
DATATYPES
DataType Examples
Integers -2, -1, 0, 1, 2, 3, 4, 5
Floating-point numbers -1.25, -1.0, --0.5, 0.0, 0.5, 1.0, 1.25
Strings 'a', 'aa', 'aaa', 'Hello!', '11 cats'
TO PRINT CHARACTERS
TYPETHE FOLLOWING:
print('c') OR print("c")
Surround characters with single quotes (') or double quotes ("),
A whole string of characters can be output like the one below
print('Hello, PYTHON PROGRAMMING IS FUN’)
You can also print a string of numbers.
Print(‘1+2+3+4+5’)
TRYTHE FOLLOWING:
print your full name
print your age
print your address
Note1:Without the quotes you will get an error message
Note2: Letter ‘p’ in print must be in lowercase
ARITHMETIC OPERATIONS ON NUMBERS
COMMANDS EXPLANATION OUTPUT
print(2 + 3) Addition 5
print(4 * 5) Multiplication 20
print(5 - 1) Subtraction 4
print(40 / 8) Division 5
print(2 ** 3) Power 8
print(25//7)
Integer division (fractional part
ignored)
2
print (25%7) Modulo (remainder left after division)
4
STRING CONCATENATION – (add two strings)
Two strings can also be added together. It just means that the
two strings are strung together.
Try this:
■ print("Hi everyone " + "Have fun with python programming")
■ print("Hi everyone " + "Have fun with python programming")
Try replicating more than two strung
STRING REPLICATION
■ (‘PYTHON’ )*5
■ print("PYTHON PROGRAMMING IS FUN" * 3)
■ print("Hi there " + ("Fun programming " * 3) + "!")
■ print("Hi there programming is fun" + "!" * 10)
If you need to put an apostrophe inside your string, you have two
ways to do it.
Using double quotes:
■ print(“Isn’t possible")
■ or escaping the apostrophe with a backslash ().
■ print(‘Isn’t possible')
PRINT IN UPPERCASE
■ print('hello'.upper() * 3 + 'hi'.upper() * 3)
■ print('hello'.upper() * 3 + 'hi'.upper())
■ print('HELLO'.upper() * 3 + 'hi')
■ print('HELLO' * 4 + 'hi'.upper())
PYTHON FUNCTIONS
■ A function is a block of code which only runs when it is called.
■ Data known as parameters, can be passed data, into a function.
■ A function can return data as a result.
■ Remember: print() prints the value an expression evaluates to?
■ The print() is a "function". It accepts parameters within the parentheses,
and does some operations on them.
■ The print(), just prints the value of the expression we give it as a parameter
within the parentheses.
A function to know the number of characters in a name:
■ print(len("Guido van Rossum "))
■ print(len("python programming is fun "))
■ print(len("actions speak louder than words "))
PYTHON OBJECTS AND METHODS
■ An object just means that it comes with its own functions.
■ Functions which come with objects are technically called methods, and are
called using a dot . after the object.
■ The strings that we've been dealing with so far are all objects — they come
with their own methods. Upper() is an example of an object.
TO SEE SOMETHING IN UPPERCASE LETTERS, TYPE:
■ print("guido van rossum ".upper())
■ Note: the syntactical difference between a function and a method:
■ Call methods with a . at the end of an object (like "I like python
programming".upper()),
■ but call a function with the string parameter placed in parentheses (like
len("I like python programming")).
CONVERTING BETWEENTYPES
How to print the number of digits in a number like 15423654?
■ If we write the code as below, what will happen.
■ print(len(15423654))
■ Try it and you will get an error. This is because the len() function expects a
string parameter, but we gave it a number.
■ Convert the number to a string before passing it to the len function, using the
str() function.
■ print(str(15423654))
■ Pass to the len() function:
■ print(len(str(15423654)))
■ The str() function can be used to convert anything to a string.
■ A similar function called int() helps us convert strings to a number.
■ Important: we can convert numbers into text, but we can't necessarily convert text into
numbers – what would int('hello') be anyway?
INSERTING COMMENTS
■ Comments are lines beginning with a # and Python will
ignore it. Comments can make your code easier for other
people to understand. There is no need to comments for
each line of code but only where something is complex.
# Set the volume to 100
volume = 100
print(volume)
VARIABLES IN PYTHON
■ Variables are used to store values. Imagine a container as a variable
where we can keep different things.
■ For example, a container of fruit.
■ We will create a variable and call it fruits and put the name of fruits inside it.
TRYTHE FOLLOWING:
“fruit”
Name
TRIAL1 TRIAL 2
name= “Fruit”
Print (name)
name = "fruit"
n = 4
print(name * n)
TRIAL3 TRIAL4
name = "Pineapple"
name = "Orange" # change the value stored in
name
print(name)
a = 5
a = a * 3
print(a) # Output: 15
a = a * a
print(a) # Output: 225
VARIABLES IN PYTHON
■ VARIABLE NAMES
■ Variables can named anything we want, such as age, grade, marks etc. but there are some restrictions:
■ It must be one word.
■ It can use only letters, numbers, and the underscore (_) character. But characters starting with underscore are not useful.
■ It must start with a letter or underscore character and cannot start with a number). For example, a1, var and var3 are allowed
[2var, 2Y etc. are not allowed].
■ It can only contains alphanumeric characters and underscores (A-Z, 0-9, and _). For example, name, name2, my_name and
myName are all allowed.
■ Is case-sensitive. For example, name and NAME are two different variables.
■ Other guidelines that are helpful when choosing variable names:
■ In general, people usually use snake case (examples - var, my_age, favorite_number) or camel case (examples - var, myAge,
favoriteNumber) when naming variables.
■ Descriptive variable names will make it easier to avoid mistakes, and easier to fix mistakes when you do make them. For
example, my_age is a much better variable name than n.
We can use variables in functions too: But what if we used the wrong name?
name = "Diesel"
print(len(name))
city = "Phoenix"
print(ctiy)
THIS IS THE END OF PART ONE
IN PART TWO WE WILL
ADDRESS:
1. THE INPUT FUNCTION
2. IF STATEMENT

More Related Content

What's hot (20)

The Ring programming language version 1.3 book - Part 11 of 88
The Ring programming language version 1.3 book - Part 11 of 88
Mahmoud Samir Fayed
 
stack and queue array implementation in java.
stack and queue array implementation in java.
CIIT Atd.
 
For Loops and Nesting in Python
For Loops and Nesting in Python
primeteacher32
 
StackArray stack3
StackArray stack3
Rajendran
 
Algoritmos ensambladores
Algoritmos ensambladores
Maurock Charolastra Muñoz
 
Learning python with flask (PyLadies Malaysia 2017 Workshop #1)
Learning python with flask (PyLadies Malaysia 2017 Workshop #1)
Sian Lerk Lau
 
Android taipei 20160225 淺談closure
Android taipei 20160225 淺談closure
Gance Zhi-Hong Zhu (朱智鴻)
 
Lab 3
Lab 3
Izzatul Safingai
 
Queue Data Structure
Queue Data Structure
Poulami Das Akuli
 
Stack Data Structure
Stack Data Structure
Poulami Das Akuli
 
6
6
EasyStudy3
 
Itroroduction to R language
Itroroduction to R language
chhabria-nitesh
 
Python and you
Python and you
Sian Lerk Lau
 
Posfix
Posfix
Fajar Baskoro
 
C program to insert a node in doubly linked list
C program to insert a node in doubly linked list
Sourav Gayen
 
Vp lecture 9 ararat
Vp lecture 9 ararat
Saman M. Almufti
 
The Ring programming language version 1.6 book - Part 22 of 189
The Ring programming language version 1.6 book - Part 22 of 189
Mahmoud Samir Fayed
 
Tu1
Tu1
Ediga Venkigowd
 
Call Execute For Everyone
Call Execute For Everyone
Daniel Boisvert
 
Put Down That Mouse
Put Down That Mouse
Daniel Boisvert
 
The Ring programming language version 1.3 book - Part 11 of 88
The Ring programming language version 1.3 book - Part 11 of 88
Mahmoud Samir Fayed
 
stack and queue array implementation in java.
stack and queue array implementation in java.
CIIT Atd.
 
For Loops and Nesting in Python
For Loops and Nesting in Python
primeteacher32
 
StackArray stack3
StackArray stack3
Rajendran
 
Learning python with flask (PyLadies Malaysia 2017 Workshop #1)
Learning python with flask (PyLadies Malaysia 2017 Workshop #1)
Sian Lerk Lau
 
Itroroduction to R language
Itroroduction to R language
chhabria-nitesh
 
C program to insert a node in doubly linked list
C program to insert a node in doubly linked list
Sourav Gayen
 
The Ring programming language version 1.6 book - Part 22 of 189
The Ring programming language version 1.6 book - Part 22 of 189
Mahmoud Samir Fayed
 
Call Execute For Everyone
Call Execute For Everyone
Daniel Boisvert
 

Similar to CODING WITH PYTHON PART 1 (20)

Copy_of_Programming_Fundamentals_CSC_104__-_Session_3.pdf
Copy_of_Programming_Fundamentals_CSC_104__-_Session_3.pdf
faridafatawu07
 
Python basics
Python basics
Hoang Nguyen
 
Python basics
Python basics
Luis Goldster
 
Python basics
Python basics
Tony Nguyen
 
Python basics
Python basics
Fraboni Ec
 
Python basics
Python basics
Harry Potter
 
Python basics
Python basics
Young Alista
 
Python basics
Python basics
James Wong
 
Python (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualize
IruolagbePius
 
BASICS OF PYTHON usefull for the student who would like to learn on their own
BASICS OF PYTHON usefull for the student who would like to learn on their own
Nandini485510
 
#Code2Create: Python Basics
#Code2Create: Python Basics
GDGKuwaitGoogleDevel
 
Python ppt
Python ppt
Anush verma
 
Python for Beginners - Simply understand programming concepts
Python for Beginners - Simply understand programming concepts
Macowtdy
 
Anton Kasyanov, Introduction to Python, Lecture3
Anton Kasyanov, Introduction to Python, Lecture3
Anton Kasyanov
 
Pythonintro
Pythonintro
Hardik Malhotra
 
VARIABLES AND DATA TYPES IN PYTHON NEED TO STUDY
VARIABLES AND DATA TYPES IN PYTHON NEED TO STUDY
Rushikesh Kolhe
 
PART 1 - Python Tutorial | Variables and Data Types in Python
PART 1 - Python Tutorial | Variables and Data Types in Python
Shivam Mitra
 
Python course
Python course
Евгений Сазонов
 
An Introduction To Python - Python Midterm Review
An Introduction To Python - Python Midterm Review
Blue Elephant Consulting
 
UNIT 4 python.pptx
UNIT 4 python.pptx
TKSanthoshRao
 
Copy_of_Programming_Fundamentals_CSC_104__-_Session_3.pdf
Copy_of_Programming_Fundamentals_CSC_104__-_Session_3.pdf
faridafatawu07
 
Python (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualize
IruolagbePius
 
BASICS OF PYTHON usefull for the student who would like to learn on their own
BASICS OF PYTHON usefull for the student who would like to learn on their own
Nandini485510
 
Python for Beginners - Simply understand programming concepts
Python for Beginners - Simply understand programming concepts
Macowtdy
 
Anton Kasyanov, Introduction to Python, Lecture3
Anton Kasyanov, Introduction to Python, Lecture3
Anton Kasyanov
 
VARIABLES AND DATA TYPES IN PYTHON NEED TO STUDY
VARIABLES AND DATA TYPES IN PYTHON NEED TO STUDY
Rushikesh Kolhe
 
PART 1 - Python Tutorial | Variables and Data Types in Python
PART 1 - Python Tutorial | Variables and Data Types in Python
Shivam Mitra
 
An Introduction To Python - Python Midterm Review
An Introduction To Python - Python Midterm Review
Blue Elephant Consulting
 
Ad

More from Buxoo Abdullah (14)

1.1.2 HEXADECIMAL
1.1.2 HEXADECIMAL
Buxoo Abdullah
 
MONEY & BANKING
MONEY & BANKING
Buxoo Abdullah
 
Retail trade
Retail trade
Buxoo Abdullah
 
1.1.3 DATA STORAGE
1.1.3 DATA STORAGE
Buxoo Abdullah
 
2.1.1 PROBLEM SOLVING & DESIGN
2.1.1 PROBLEM SOLVING & DESIGN
Buxoo Abdullah
 
1.1.1 BINARY SYSTEM
1.1.1 BINARY SYSTEM
Buxoo Abdullah
 
COMPUTER SCIENCE PRE RELEASE 2210 FOR NOVEMBER 2018 P22
COMPUTER SCIENCE PRE RELEASE 2210 FOR NOVEMBER 2018 P22
Buxoo Abdullah
 
Computer health & safety issues
Computer health & safety issues
Buxoo Abdullah
 
Program & language generation
Program & language generation
Buxoo Abdullah
 
Data and information
Data and information
Buxoo Abdullah
 
Computer languages
Computer languages
Buxoo Abdullah
 
Input devices
Input devices
Buxoo Abdullah
 
Formative & summative evaluation
Formative & summative evaluation
Buxoo Abdullah
 
Ppt presentation of queues
Ppt presentation of queues
Buxoo Abdullah
 
2.1.1 PROBLEM SOLVING & DESIGN
2.1.1 PROBLEM SOLVING & DESIGN
Buxoo Abdullah
 
COMPUTER SCIENCE PRE RELEASE 2210 FOR NOVEMBER 2018 P22
COMPUTER SCIENCE PRE RELEASE 2210 FOR NOVEMBER 2018 P22
Buxoo Abdullah
 
Computer health & safety issues
Computer health & safety issues
Buxoo Abdullah
 
Program & language generation
Program & language generation
Buxoo Abdullah
 
Formative & summative evaluation
Formative & summative evaluation
Buxoo Abdullah
 
Ppt presentation of queues
Ppt presentation of queues
Buxoo Abdullah
 
Ad

Recently uploaded (20)

Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
Sustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive Learning
Leonel Morgado
 
Publishing Your Memoir with Brooke Warner
Publishing Your Memoir with Brooke Warner
Brooke Warner
 
Nice Dream.pdf /
Nice Dream.pdf /
ErinUsher3
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
Revista digital preescolar en transformación
Revista digital preescolar en transformación
guerragallardo26
 
What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
Belicia R.S
 
LDMMIA GRAD Student Check-in Orientation Sampler
LDMMIA GRAD Student Check-in Orientation Sampler
LDM & Mia eStudios
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
The Man In The Back – Exceptional Delaware.pdf
The Man In The Back – Exceptional Delaware.pdf
dennisongomezk
 
GEOGRAPHY-Study Material [ Class 10th] .pdf
GEOGRAPHY-Study Material [ Class 10th] .pdf
SHERAZ AHMAD LONE
 
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
Quiz Club of PSG College of Arts & Science
 
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
What is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptx
Ramakrishna Reddy Bijjam
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
Sustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive Learning
Leonel Morgado
 
Publishing Your Memoir with Brooke Warner
Publishing Your Memoir with Brooke Warner
Brooke Warner
 
Nice Dream.pdf /
Nice Dream.pdf /
ErinUsher3
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
Revista digital preescolar en transformación
Revista digital preescolar en transformación
guerragallardo26
 
What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
Belicia R.S
 
LDMMIA GRAD Student Check-in Orientation Sampler
LDMMIA GRAD Student Check-in Orientation Sampler
LDM & Mia eStudios
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
The Man In The Back – Exceptional Delaware.pdf
The Man In The Back – Exceptional Delaware.pdf
dennisongomezk
 
GEOGRAPHY-Study Material [ Class 10th] .pdf
GEOGRAPHY-Study Material [ Class 10th] .pdf
SHERAZ AHMAD LONE
 
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
What is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptx
Ramakrishna Reddy Bijjam
 

CODING WITH PYTHON PART 1

  • 1. CODING WITH PYTHON Part one Printing string, Functions, object & method, Converting between types, adding comments and Variables
  • 2. WHICH PROGRAM TO USE? • I have used Jupyter notebook from Anaconda navigator. • I find it easy to use and user friendly. • It needs Mozilla firefox to be installed • But it takes a lot of time to download and installed (some 15 to 25 minutes based on the speed of your PC) but once installed it is quick to use.
  • 3. THE INTERFACE WILL BE AS FOLLOWS
  • 4. I WILL NOT EXPLAINED HOW TO INSTALL THIS SOFTWARE YOU CAN GET A DEMONSTRATION ON YOUTUBE
  • 5. LIST OF ALL ARITHMETIC OPERATIONS SUPPORTED BY PYTHON.TRYTHE FOLLOWING MEANING OUTPUT 2 + 3 * 6 20 (2 + 3) * 6 30 2 ** 8 256 23 // 7 Integer division (fractional part ignored) 3 23%7 Modulo (remainder left after division) 2 (5 - 1) * ((7 + 1) / (3 - 1)) 16.0 DATATYPES DataType Examples Integers -2, -1, 0, 1, 2, 3, 4, 5 Floating-point numbers -1.25, -1.0, --0.5, 0.0, 0.5, 1.0, 1.25 Strings 'a', 'aa', 'aaa', 'Hello!', '11 cats'
  • 6. TO PRINT CHARACTERS TYPETHE FOLLOWING: print('c') OR print("c") Surround characters with single quotes (') or double quotes ("), A whole string of characters can be output like the one below print('Hello, PYTHON PROGRAMMING IS FUN’) You can also print a string of numbers. Print(‘1+2+3+4+5’) TRYTHE FOLLOWING: print your full name print your age print your address Note1:Without the quotes you will get an error message Note2: Letter ‘p’ in print must be in lowercase
  • 7. ARITHMETIC OPERATIONS ON NUMBERS COMMANDS EXPLANATION OUTPUT print(2 + 3) Addition 5 print(4 * 5) Multiplication 20 print(5 - 1) Subtraction 4 print(40 / 8) Division 5 print(2 ** 3) Power 8 print(25//7) Integer division (fractional part ignored) 2 print (25%7) Modulo (remainder left after division) 4
  • 8. STRING CONCATENATION – (add two strings) Two strings can also be added together. It just means that the two strings are strung together. Try this: ■ print("Hi everyone " + "Have fun with python programming") ■ print("Hi everyone " + "Have fun with python programming") Try replicating more than two strung
  • 9. STRING REPLICATION ■ (‘PYTHON’ )*5 ■ print("PYTHON PROGRAMMING IS FUN" * 3) ■ print("Hi there " + ("Fun programming " * 3) + "!") ■ print("Hi there programming is fun" + "!" * 10) If you need to put an apostrophe inside your string, you have two ways to do it. Using double quotes: ■ print(“Isn’t possible") ■ or escaping the apostrophe with a backslash (). ■ print(‘Isn’t possible')
  • 10. PRINT IN UPPERCASE ■ print('hello'.upper() * 3 + 'hi'.upper() * 3) ■ print('hello'.upper() * 3 + 'hi'.upper()) ■ print('HELLO'.upper() * 3 + 'hi') ■ print('HELLO' * 4 + 'hi'.upper())
  • 11. PYTHON FUNCTIONS ■ A function is a block of code which only runs when it is called. ■ Data known as parameters, can be passed data, into a function. ■ A function can return data as a result. ■ Remember: print() prints the value an expression evaluates to? ■ The print() is a "function". It accepts parameters within the parentheses, and does some operations on them. ■ The print(), just prints the value of the expression we give it as a parameter within the parentheses. A function to know the number of characters in a name: ■ print(len("Guido van Rossum ")) ■ print(len("python programming is fun ")) ■ print(len("actions speak louder than words "))
  • 12. PYTHON OBJECTS AND METHODS ■ An object just means that it comes with its own functions. ■ Functions which come with objects are technically called methods, and are called using a dot . after the object. ■ The strings that we've been dealing with so far are all objects — they come with their own methods. Upper() is an example of an object. TO SEE SOMETHING IN UPPERCASE LETTERS, TYPE: ■ print("guido van rossum ".upper()) ■ Note: the syntactical difference between a function and a method: ■ Call methods with a . at the end of an object (like "I like python programming".upper()), ■ but call a function with the string parameter placed in parentheses (like len("I like python programming")).
  • 13. CONVERTING BETWEENTYPES How to print the number of digits in a number like 15423654? ■ If we write the code as below, what will happen. ■ print(len(15423654)) ■ Try it and you will get an error. This is because the len() function expects a string parameter, but we gave it a number. ■ Convert the number to a string before passing it to the len function, using the str() function. ■ print(str(15423654)) ■ Pass to the len() function: ■ print(len(str(15423654))) ■ The str() function can be used to convert anything to a string. ■ A similar function called int() helps us convert strings to a number. ■ Important: we can convert numbers into text, but we can't necessarily convert text into numbers – what would int('hello') be anyway?
  • 14. INSERTING COMMENTS ■ Comments are lines beginning with a # and Python will ignore it. Comments can make your code easier for other people to understand. There is no need to comments for each line of code but only where something is complex. # Set the volume to 100 volume = 100 print(volume)
  • 15. VARIABLES IN PYTHON ■ Variables are used to store values. Imagine a container as a variable where we can keep different things. ■ For example, a container of fruit. ■ We will create a variable and call it fruits and put the name of fruits inside it. TRYTHE FOLLOWING: “fruit” Name TRIAL1 TRIAL 2 name= “Fruit” Print (name) name = "fruit" n = 4 print(name * n) TRIAL3 TRIAL4 name = "Pineapple" name = "Orange" # change the value stored in name print(name) a = 5 a = a * 3 print(a) # Output: 15 a = a * a print(a) # Output: 225
  • 16. VARIABLES IN PYTHON ■ VARIABLE NAMES ■ Variables can named anything we want, such as age, grade, marks etc. but there are some restrictions: ■ It must be one word. ■ It can use only letters, numbers, and the underscore (_) character. But characters starting with underscore are not useful. ■ It must start with a letter or underscore character and cannot start with a number). For example, a1, var and var3 are allowed [2var, 2Y etc. are not allowed]. ■ It can only contains alphanumeric characters and underscores (A-Z, 0-9, and _). For example, name, name2, my_name and myName are all allowed. ■ Is case-sensitive. For example, name and NAME are two different variables. ■ Other guidelines that are helpful when choosing variable names: ■ In general, people usually use snake case (examples - var, my_age, favorite_number) or camel case (examples - var, myAge, favoriteNumber) when naming variables. ■ Descriptive variable names will make it easier to avoid mistakes, and easier to fix mistakes when you do make them. For example, my_age is a much better variable name than n. We can use variables in functions too: But what if we used the wrong name? name = "Diesel" print(len(name)) city = "Phoenix" print(ctiy)
  • 17. THIS IS THE END OF PART ONE IN PART TWO WE WILL ADDRESS: 1. THE INPUT FUNCTION 2. IF STATEMENT