SlideShare a Scribd company logo
2
Most read
8
Most read
12
Most read
PYTHON BASICS
Basics
1) To output simple use print :
print(‘Hello World’)
2)When you put the string in triple quotes, it will be displayed
the way you have the string in the text editor
print(“””The output would be in !
MULTIPLE LINES”””)
or you could just use n
3) In Python we use a # to indicate comments :
#This is a comment
print('Hello World’)
4)
Taking Input
firstName = input("What is your first name? ")
lastName = input("What is your last name? " )
print("Hello" + firstName + lastName)
Strings and methods to manipulate them
message = 'Hello world'
print(message.lower())
print(message.upper())
print(message.swapcase())
print(message.find('world'))
print(message.count('o'))
print(message.capitalize())
print(message.replace('Hello','Hi'))
Type Conversion
. Ex:-
salary = input("Please enter your salary: ")
bonus = input("Please enter your bonus: ")
payCheck = salary + bonus
print(payCheck)
. How to:-
int(value) converts to an integer
long(value) converts to a long integer
etc.
Working with dates
• The datetime class allows us to get the current date and time
• Ex:-
import datetime
currentDate = datetime.date.today()
print (currentDate)
print (currentDate.year)
print (currentDate.month)
print (currentDate.day)
print (currentDate.strftime('%d %b,%Y’))
print (currentDate.strftime
('Please attend our event %A, %B %d in the year %Y'))
• %d is the day of the month
• %b is the abbreviation for the month
• %Y is the 4 digit year
• For more you can visit strftime.org
• To add or subtract days or hours or minutes, use timedelta method
print (currentDate + datetime.timedelta(days=-15))
What about times?
• It is called Datetime, so yes, it can store times.
import datetime
currentTime = datetime.datetime.now()
print (currentTime)
print (currentTime.hour)
print (currentTime.minute)
print (currentTime.second)
print (datetime.datetime.strftime(currentTime,’%H:%M'))
%H Hours (24 hr clock)
%I Hours (12 hr clock)
%p AM or PM
%m Minutes
%S Seconds
Making decisions
-if os is not None :
print(“Amazing choice”)
elif not os == "windows" :
print(“Amazing choice again ! ”)
else:
print(“Joke Joke ! ”)
-if saturday or sunday :
print(“Beer")
-if wednesday and yourSession :
print("DAMN")
LOOOOOOPS
-for steps in range(1,4) :
print(steps)
output- 1 2 3
-for steps in range(4) :
print(steps)
output- 0 1 2 3
-for steps in range(1,10,2) :
print(steps)
output- 1 3 5 7 9
-for steps in [1,2,3,4,5] :
print(steps)
Phun with loops and turtle
import turtle
for steps in ['red','blue','green','black'] :
turtle.color(steps)
turtle.forward(100)
turtle.right(90)
List
• Ex [0], [2.3,4.5],[5,”hello”,9.8]
• Use len to get the length of list ex:-
Example:- names=[“amit”,”divyansh”,”kshitij”]
len(names)
output=3
List Methods
laptops = [‘Blade','Alienware','Macbook','MSI']
#add a new value to the end of the list
laptops.append('Microsoft')
#display the last value in the list
print(laptops[-1])
#remove a value from the lust
laptops.remove('Alienware')
#delete the first item in the list
del laptops[0]
#print the first item in the list
print(laptops[0])
#this will return the index in the list
print(laptops.index(‘Macbook'))
#Sort the names in alphabetical order
laptops.sort()
#Others
laptops.upper(), laptops.lower()
Exception Handling
first = input("Enter the first number ")
second = input("Enter the second number ")
firstNumber = float(first)
secondNumber = float(second)
try :
result = firstNumber / secondNumber
print (first + " / " + second + " = " + str(result))
except Exception as e:
print(e)
– https://docs.python.org/3/c-api/exceptions.html#standard-
exceptions

More Related Content

PPTX
File Handling Python
PDF
Python Variable Types, List, Tuple, Dictionary
PDF
Python Programming
PDF
Python basic
PPTX
List in Python
PPTX
Functions in python slide share
File Handling Python
Python Variable Types, List, Tuple, Dictionary
Python Programming
Python basic
List in Python
Functions in python slide share

What's hot (20)

PPTX
Python Flow Control
PPTX
Python Data-Types
PPT
Standard Library Functions
PPT
Python ppt
PPTX
Functions in Python
PPTX
Python Tutorial Part 1
PDF
Arrays in python
PDF
Set methods in python
PPTX
Data types in python
PPTX
Object oriented programming in python
PPTX
FLOW OF CONTROL-INTRO PYTHON
PDF
Python functions
PDF
Python list
PPTX
queue & its applications
PPTX
Python for loop
PDF
pandas - Python Data Analysis
PDF
Datatypes in python
PPTX
Python array
PPT
Exception handling and function in python
PPTX
Python variables and data types.pptx
Python Flow Control
Python Data-Types
Standard Library Functions
Python ppt
Functions in Python
Python Tutorial Part 1
Arrays in python
Set methods in python
Data types in python
Object oriented programming in python
FLOW OF CONTROL-INTRO PYTHON
Python functions
Python list
queue & its applications
Python for loop
pandas - Python Data Analysis
Datatypes in python
Python array
Exception handling and function in python
Python variables and data types.pptx
Ad

Viewers also liked (20)

PPTX
Python basics
PPT
Grails Plugins
PPTX
PPTX
Grails Services
PPTX
Config BuildConfig
PPT
PPT
Linux Introduction
PPT
Introduction to Grails
ODP
PPTX
Meta Programming in Groovy
PPTX
Introduction to mongo db
PDF
Unit test-using-spock in Grails
PPTX
MetaProgramming with Groovy
PPTX
Grails Plugins(Console, DB Migration, Asset Pipeline and Remote pagination)
PPTX
Actors model in gpars
Python basics
Grails Plugins
Grails Services
Config BuildConfig
Linux Introduction
Introduction to Grails
Meta Programming in Groovy
Introduction to mongo db
Unit test-using-spock in Grails
MetaProgramming with Groovy
Grails Plugins(Console, DB Migration, Asset Pipeline and Remote pagination)
Actors model in gpars
Ad

Similar to Python basics (20)

PDF
Python programming : Standard Input and Output
PDF
3.Pi for Python
PDF
Python Menu
PDF
Are we ready to Go?
PPTX
inputoutput.pptx
ODP
Python quickstart for programmers: Python Kung Fu
PPTX
Programming ppt files (final)
PPTX
Dts x dicoding #2 memulai pemrograman kotlin
PPTX
Python variables in the computer science.pptx
PPTX
Psuedocode1, algorithm1, Flowchart1.pptx
PDF
Go ahead, make my day
PPT
python fundamental for beginner course .ppt
PDF
LOOPS TOPIC FOR CLASS XI PYTHON SYLLABUS
PDF
InterConnect: Server Side Swift for Java Developers
PPTX
Iteration
PDF
[EN] Ada Lovelace Day 2014 - Tampon run
PDF
The Ring programming language version 1.6 book - Part 26 of 189
PPTX
module 3 BTECH FIRST YEAR ATP APJ KTU PYTHON
PPTX
Class 12 computer. 1 Python intro-1.pptx
PPTX
Pythonlearn-03-Conditional.pptx
Python programming : Standard Input and Output
3.Pi for Python
Python Menu
Are we ready to Go?
inputoutput.pptx
Python quickstart for programmers: Python Kung Fu
Programming ppt files (final)
Dts x dicoding #2 memulai pemrograman kotlin
Python variables in the computer science.pptx
Psuedocode1, algorithm1, Flowchart1.pptx
Go ahead, make my day
python fundamental for beginner course .ppt
LOOPS TOPIC FOR CLASS XI PYTHON SYLLABUS
InterConnect: Server Side Swift for Java Developers
Iteration
[EN] Ada Lovelace Day 2014 - Tampon run
The Ring programming language version 1.6 book - Part 26 of 189
module 3 BTECH FIRST YEAR ATP APJ KTU PYTHON
Class 12 computer. 1 Python intro-1.pptx
Pythonlearn-03-Conditional.pptx

More from NexThoughts Technologies (20)

PDF
PDF
Docker & kubernetes
PDF
Apache commons
PDF
Microservice Architecture using Spring Boot with React & Redux
PDF
Solid Principles
PDF
Introduction to TypeScript
PDF
Smart Contract samples
PDF
My Doc of geth
PDF
Geth important commands
PDF
Ethereum genesis
PPTX
Springboot Microservices
PDF
An Introduction to Redux
PPTX
Google authentication
Docker & kubernetes
Apache commons
Microservice Architecture using Spring Boot with React & Redux
Solid Principles
Introduction to TypeScript
Smart Contract samples
My Doc of geth
Geth important commands
Ethereum genesis
Springboot Microservices
An Introduction to Redux
Google authentication

Recently uploaded (20)

PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Empathic Computing: Creating Shared Understanding
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPT
Teaching material agriculture food technology
PDF
Electronic commerce courselecture one. Pdf
PPTX
Spectroscopy.pptx food analysis technology
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Big Data Technologies - Introduction.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Approach and Philosophy of On baking technology
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Encapsulation_ Review paper, used for researhc scholars
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
sap open course for s4hana steps from ECC to s4
Empathic Computing: Creating Shared Understanding
Dropbox Q2 2025 Financial Results & Investor Presentation
Digital-Transformation-Roadmap-for-Companies.pptx
MYSQL Presentation for SQL database connectivity
“AI and Expert System Decision Support & Business Intelligence Systems”
Teaching material agriculture food technology
Electronic commerce courselecture one. Pdf
Spectroscopy.pptx food analysis technology
MIND Revenue Release Quarter 2 2025 Press Release
Building Integrated photovoltaic BIPV_UPV.pdf
Programs and apps: productivity, graphics, security and other tools
Big Data Technologies - Introduction.pptx
Network Security Unit 5.pdf for BCA BBA.
NewMind AI Weekly Chronicles - August'25 Week I
Approach and Philosophy of On baking technology
Advanced methodologies resolving dimensionality complications for autism neur...
The AUB Centre for AI in Media Proposal.docx
Encapsulation_ Review paper, used for researhc scholars

Python basics

  • 2. Basics 1) To output simple use print : print(‘Hello World’) 2)When you put the string in triple quotes, it will be displayed the way you have the string in the text editor print(“””The output would be in ! MULTIPLE LINES”””) or you could just use n 3) In Python we use a # to indicate comments : #This is a comment print('Hello World’) 4)
  • 3. Taking Input firstName = input("What is your first name? ") lastName = input("What is your last name? " ) print("Hello" + firstName + lastName)
  • 4. Strings and methods to manipulate them message = 'Hello world' print(message.lower()) print(message.upper()) print(message.swapcase()) print(message.find('world')) print(message.count('o')) print(message.capitalize()) print(message.replace('Hello','Hi'))
  • 5. Type Conversion . Ex:- salary = input("Please enter your salary: ") bonus = input("Please enter your bonus: ") payCheck = salary + bonus print(payCheck) . How to:- int(value) converts to an integer long(value) converts to a long integer etc.
  • 6. Working with dates • The datetime class allows us to get the current date and time • Ex:- import datetime currentDate = datetime.date.today() print (currentDate) print (currentDate.year) print (currentDate.month) print (currentDate.day) print (currentDate.strftime('%d %b,%Y’)) print (currentDate.strftime ('Please attend our event %A, %B %d in the year %Y')) • %d is the day of the month • %b is the abbreviation for the month • %Y is the 4 digit year • For more you can visit strftime.org • To add or subtract days or hours or minutes, use timedelta method print (currentDate + datetime.timedelta(days=-15))
  • 7. What about times? • It is called Datetime, so yes, it can store times. import datetime currentTime = datetime.datetime.now() print (currentTime) print (currentTime.hour) print (currentTime.minute) print (currentTime.second) print (datetime.datetime.strftime(currentTime,’%H:%M')) %H Hours (24 hr clock) %I Hours (12 hr clock) %p AM or PM %m Minutes %S Seconds
  • 8. Making decisions -if os is not None : print(“Amazing choice”) elif not os == "windows" : print(“Amazing choice again ! ”) else: print(“Joke Joke ! ”) -if saturday or sunday : print(“Beer") -if wednesday and yourSession : print("DAMN")
  • 9. LOOOOOOPS -for steps in range(1,4) : print(steps) output- 1 2 3 -for steps in range(4) : print(steps) output- 0 1 2 3 -for steps in range(1,10,2) : print(steps) output- 1 3 5 7 9 -for steps in [1,2,3,4,5] : print(steps)
  • 10. Phun with loops and turtle import turtle for steps in ['red','blue','green','black'] : turtle.color(steps) turtle.forward(100) turtle.right(90)
  • 11. List • Ex [0], [2.3,4.5],[5,”hello”,9.8] • Use len to get the length of list ex:- Example:- names=[“amit”,”divyansh”,”kshitij”] len(names) output=3
  • 12. List Methods laptops = [‘Blade','Alienware','Macbook','MSI'] #add a new value to the end of the list laptops.append('Microsoft') #display the last value in the list print(laptops[-1]) #remove a value from the lust laptops.remove('Alienware') #delete the first item in the list del laptops[0] #print the first item in the list print(laptops[0]) #this will return the index in the list print(laptops.index(‘Macbook')) #Sort the names in alphabetical order laptops.sort() #Others laptops.upper(), laptops.lower()
  • 13. Exception Handling first = input("Enter the first number ") second = input("Enter the second number ") firstNumber = float(first) secondNumber = float(second) try : result = firstNumber / secondNumber print (first + " / " + second + " = " + str(result)) except Exception as e: print(e) – https://docs.python.org/3/c-api/exceptions.html#standard- exceptions