Introduction To Python
Introduction To Python
Introduction To Python
Read Courses Practice Video Jobs
Python is a programming language that lets you work quickly and integrate
systems more efficiently.
There are two major Python versions: Python 2 and Python 3. Both are
quite different.
1) Finding an Interpreter:
1200+ have already taken up the challenge. It's your turn now! Get 90% refund
on course fees upon achieving 90% completion.Discover How
We use cookies to ensure you have the best browsing experience on our website. By using
our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Got It !
Policy
https://www.geeksforgeeks.org/introduction-to-python/ 1/21
1/30/24, 4:29 PM Introduction To Python - GeeksforGeeks
Windows: There are many interpreters available freely to run Python scripts
like IDLE (Integrated Development Environment) that comes bundled with
the Python software downloaded from http://python.org/.
Linux: Python comes preinstalled with popular Linux distros such as Ubuntu
and Fedora. To check which version of Python you’re running, type “python”
in the terminal emulator. The interpreter should start and print the version
number.
macOS: Generally, Python 2.7 comes bundled with macOS. You’ll have to
manually install Python 3 from http://python.org/.
Just type in the following code after you start the interpreter.
# Script Begins
print("GeeksQuiz")
# Scripts Ends
Output:
GeeksQuiz
https://www.geeksforgeeks.org/introduction-to-python/ 2/21
1/30/24, 4:29 PM Introduction To Python - GeeksforGeeks
Prerequisites:
LANGUAGE FEATURES
Interpreted
There are no separate compilation and execution steps like C and C++.
Directly run the program from the source code.
Internally, Python converts the source code into an intermediate form
called bytecodes which is then translated into native language of
specific computer to run it.
No need to worry about linking and loading with libraries, etc.
Platform Independent
Python programs can be developed and executed on multiple
We use cookies to ensure you have the best browsing experience on our website. By using
operating system platforms.
our site, you acknowledge that you have read and understood our Cookie Policy & Privacy
Policy
https://www.geeksforgeeks.org/introduction-to-python/ 3/21
1/30/24, 4:29 PM Introduction To Python - GeeksforGeeks
Python vs JAVA
We use cookies to ensure you have the best browsing experience on our website. By using
our site, you acknowledge that you have read and understood our Cookie Policy & Privacy
Policy
https://www.geeksforgeeks.org/introduction-to-python/ 4/21
1/30/24, 4:29 PM Introduction To Python - GeeksforGeeks
Python Java
Statically Typed
Dynamically Typed
All variable names (along with their
No need to declare anything. An
types) must be explicitly declared.
assignment statement binds a
Attempting to assign an object of the
name to an object, and the
wrong type to a variable name triggers a
object can be of any type.
type exception.
No type casting is required
Type casting is required when using
when using container objects
container objects.
Python Code
print("Hello, world!")
https://www.geeksforgeeks.org/introduction-to-python/ 5/21
1/30/24, 4:29 PM Introduction To Python - GeeksforGeeks
GUI
https://www.geeksforgeeks.org/introduction-to-python/ 6/21
1/30/24, 4:29 PM Introduction To Python - GeeksforGeeks
Pros:
1. Ease of use
2. Multi-paradigm Approach
Cons:
Industrial Importance
Most of the companies are now looking for candidates who know about
Python Programming. Those having the knowledge of python may have
more chances of impressing the interviewing panel. So I would suggest that
beginners should start learning python and excel in it.
https://www.geeksforgeeks.org/introduction-to-python/ 7/21
1/30/24, 4:29 PM Introduction To Python - GeeksforGeeks
Advantages :
Applications :
https://www.geeksforgeeks.org/introduction-to-python/ 8/21
1/30/24, 4:29 PM Introduction To Python - GeeksforGeeks
print("Hello World")
Note: Please note that Python for its scope doesn’t depend on the braces ( {
} ), instead it uses indentation for its scope.
Now moving on further Lets start our basics of Python . I will be covering
the basics in some small sections. Just go through them and trust me you’ll
learn the basics of Python very easily.
We use cookies to ensure you have the best browsing experience on our website. By using
our site, you acknowledge that you have read and understood our Cookie Policy & Privacy
Policy
https://www.geeksforgeeks.org/introduction-to-python/ 9/21
1/30/24, 4:29 PM Introduction To Python - GeeksforGeeks
2. If you are on Linux/Unix-like just open the terminal and on 99% linux OS
Python comes preinstalled with the OS.Just type ‘python3’ in terminal
and you are ready to go.
It will look like this :
The ” >>> ” represents the python shell and its ready to take python
commands and code.
In other programming languages like C, C++, and Java, you will need to
declare the type of variables but in Python you don’t need to do that. Just
type in the variable and when values will be given to it, then it will
automatically know whether the value given would be an int, float, or char
We useorcookies
eventoaensure you have the best browsing experience on our website. By using
String.
our site, you acknowledge that you have read and understood our Cookie Policy & Privacy
Policy
https://www.geeksforgeeks.org/introduction-to-python/ 10/21
1/30/24, 4:29 PM Introduction To Python - GeeksforGeeks
myNumber2 = 4.5
print(myNumber2)
myNumber ="helloworld"
print(myNumber)
Output:
3
4.5
helloworld
See, how simple is it, just create a variable and assign it any value you want
and then use the print function to print it. Python have 4 types of built in
Data Structures namely List, Dictionary, Tuple and Set.
List is the most basic Data Structure in python. List is a mutable data
structure i.e items can be added to list later after the list creation. It’s like you
are going to shop at the local market and made a list of some items and later
on you can add more and more items to the list.
append() function is used to add data to the list.
print(nums)
Output:
https://www.geeksforgeeks.org/introduction-to-python/ 11/21
1/30/24, 4:29 PM Introduction To Python - GeeksforGeeks
In this section, we will learn how to take input from the user and hence
manipulate it or simply display it. input() function is used to take input from
the user.
Output:
hello harssh
Output:
Selection
Selection in Python is made using the two keywords ‘if’ and ‘elif’ and else
(elseif)
We use# cookies
Python program
to ensure to illustrate
you have the best browsing experience on our website. By using
# selection statement
our site, you acknowledge that you have read and understood our Cookie Policy & Privacy
Policy
num1 = 34
https://www.geeksforgeeks.org/introduction-to-python/ 12/21
1/30/24, 4:29 PM Introduction To Python - GeeksforGeeks
if(num1>12):
print("Num1 is good")
elif(num1>35):
print("Num2 is not gooooo....")
else:
print("Num2 is great")
Output:
Num1 is good
Functions
def function-name(arguments):
#function body
# calling function
hello()
Output:
hello
hello again
hello
hello again
We use# cookies to ensure you have the best browsing experience on our website. By using
Python program to illustrate
our site, you acknowledge
# function with main
that you have read and understood our Cookie Policy & Privacy
Policy
def getInteger():
https://www.geeksforgeeks.org/introduction-to-python/ 13/21
1/30/24, 4:29 PM Introduction To Python - GeeksforGeeks
def Main():
print("Started")
Output:
Started
Enter integer: 5
Iteration (Looping)
As the name suggests it calls repeating things again and again. We will use
the most popular ‘for’ loop here.
Output:
0
1
2
3
4
Modules
Python has a very rich module library that has several functions to do many
We usetasks.
cookiesYou canyou
to ensure read
havemore
the bestabout Python’s
browsing experience standard library
on our website. By usingby Clicking here
our site, you acknowledge that you have read and understood our Cookie Policy & Privacy
Policy
https://www.geeksforgeeks.org/introduction-to-python/ 14/21
1/30/24, 4:29 PM Introduction To Python - GeeksforGeeks
def Main():
num = -85
if __name__=="__main__":
Main()
Output:
85.0
Related Courses
New to the programming world, don’t know where to start? Start with
beginner-friendly Python Programming Foundation -Self Paced Course
designed for absolute beginners who wish to kickstart and build their
foundations in Python programming language. Learn Python basics,
Variables & Data types, Operators etc and learn how to solve coding
problems efficiently in Python. Don’t wait, sign up now and kickstart
your Python journey today.
If you’re curious to upgrade your Python skills, you’ve come to the right
We use cookies to ensure you have the best browsing experience on our website. By using
platform!
our site, you In that
acknowledge thisyou
DS Using
have Python
read and Programming
understood our Cookie Policy–& Self
PrivacyPaced Course,
Policy
designed for Python enthusiasts where you’ll be guided by the leading
https://www.geeksforgeeks.org/introduction-to-python/ 15/21
1/30/24, 4:29 PM Introduction To Python - GeeksforGeeks
Don't miss your chance to ride the wave of the data revolution! Every
industry is scaling new heights by tapping into the power of data. Sharpen
your skills and become a part of the hottest trend in the 21st century.
Dive into the future of technology - explore the Complete Machine Learning
and Data Science Program by GeeksforGeeks and stay ahead of the curve.
Previous Next
Similar Reads
Introduction to Simulation Modeling in Introduction to Kivy ; A Cross-platform
Python Python Framework
https://www.geeksforgeeks.org/introduction-to-python/ 16/21
1/30/24, 4:29 PM Introduction To Python - GeeksforGeeks
Complete Tutorials
Python Crash Course Python API Tutorial: Getting Started
with APIs
GeeksforGeeks
Additional Information
1200+ have already taken up the challenge. It's your turn now! Get 90% refund
on course fees upon achieving 90% completion.Discover How
We use cookies to ensure you have the best browsing experience on our website. By using
our site, you acknowledge that you have read and understood our Cookie Policy & Privacy
Policy
https://www.geeksforgeeks.org/introduction-to-python/ 17/21
1/30/24, 4:29 PM Introduction To Python - GeeksforGeeks
Company Explore
About Us Job-A-Thon Hiring Challenge
Legal Hack-A-Thon
Careers GfG Weekly Contest
In Media Offline Classes (Delhi/NCR)
Contact Us DSA in JAVA/C++
Advertise with us Master System Design
GFG Corporate Solution Master CP
Placement Training Program GeeksforGeeks Videos
Apply for Mentor Geeks Community
Languages DSA
Python Data Structures
Java Algorithms
C++ DSA for Beginners
PHP Basic DSA Problems
GoLang DSA Roadmap
SQL Top 100 DSA Interview Problems
R Language DSA Roadmap by Sandeep Jain
Android Tutorial All Cheat Sheets
Tutorials Archive
https://www.geeksforgeeks.org/introduction-to-python/ 18/21
1/30/24, 4:29 PM Introduction To Python - GeeksforGeeks
https://www.geeksforgeeks.org/introduction-to-python/ 19/21
1/30/24, 4:29 PM Introduction To Python - GeeksforGeeks
Class 9 Biology
Class 8 Social Science
Complete Study Material English Grammar
Colleges Companies
Indian Colleges Admission & Campus Experiences META Owned Companies
List of Central Universities - In India Alphabhet Owned Companies
Colleges in Delhi University TATA Group Owned Companies
IIT Colleges Reliance Owned Companies
NIT Colleges
IIIT Colleges
https://www.geeksforgeeks.org/introduction-to-python/ 20/21
1/30/24, 4:29 PM Introduction To Python - GeeksforGeeks
We use cookies to ensure you have the best browsing experience on our website. By using
our site, you acknowledge that you have read and understood our Cookie Policy & Privacy
Policy
https://www.geeksforgeeks.org/introduction-to-python/ 21/21