0% found this document useful (0 votes)
13 views13 pages

Python 1

Python is an object-oriented, high-level programming language known for its ease of use and extensive libraries. Key features include being open-source, portable, and dynamically typed, making it suitable for various applications including GUI programming. The document also covers installation, basic syntax, and how to run Python programs using an interactive interpreter or script files.

Uploaded by

daksham2005
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)
13 views13 pages

Python 1

Python is an object-oriented, high-level programming language known for its ease of use and extensive libraries. Key features include being open-source, portable, and dynamically typed, making it suitable for various applications including GUI programming. The document also covers installation, basic syntax, and how to run Python programs using an interactive interpreter or script files.

Uploaded by

daksham2005
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
You are on page 1/ 13

Programming in Python

What is Python?
 Python is an object-oriented programming language that is
designed in C.
 it is a high-level programming language that allows for the creation
of both simple as well as complex operations.
 Along with this ,Python comes inbuilt with a wide array of modules as
well as libraries which allows it to support many different
programming languages like Java, C, and C++
Python Features
 1. Easy to code:
Python is a high-level programming language. It is very easy to learn the
language as compared to other languages like C, C#, Javascript, Java, etc. It is
also a developer-friendly language.
 2. Free and Open Source:
Python language is freely available at the official website .Since it is open-source, this
means that source code is also available to the public. So you can download it as,
use it as well as share it.
 3. Object-Oriented Language:
One of the key features of python is Object-Oriented programming. Python supports
object-oriented language and concepts of classes, objects encapsulation, etc
 4. GUI Programming Support:
GUI or Graphical User Interface is one of the key aspects of any programming
language because it has the ability to add flair to code and make the results
more visual. Python has support for a wide array of GUIs which can easily be imported
to the interpreter, thus making this one of the most favorite languages for developers.
Graphical User interfaces can be made using a module such as PyQt5, PyQt4,
wxPython, or Tk in python.
Python Features

 5. Python is Portable language:


Python language is also a portable language. For example, if we
have python code for windows and if we want to run this code on
other platforms such as Linux, Unix, and Mac then we do not need
to change it, we can run this code on any platform.
 6. Python is Integrated language:
Python is also an Integrated language because we can easily
integrated python with other languages like c, c++, etc.
 7. Interpreted Language:
Python is an Interpreted Language because Python code is
executed line by line at a time. like other languages C, C++, Java,
etc. there is no need to compile python code this makes it easier to
debug our code. The source code of python is converted into an
immediate form called bytecode.
Python Features
 8. Large Standard Library
Python has a large standard library which provides a rich set of
module and functions so you do not have to write your own code
for every single thing. There are many libraries present in python for
such as regular expressions, unit-testing, web browsers, etc.
 9. Dynamically Typed Language:
Python is a dynamically-typed language. That means the type (for
example- int, double, long, etc.) for a variable is decided at run
time not in advance because of this feature we don’t need to
specify the type of variable
Installation on Windows

 Visit the linkhttps://www.python.org/downloads/ to download the


latest release of Python. In this process, we will install Python 3.8 on
our Windows operating system.
First Python Program

Python provides us the two ways to run a program:


 Using Interactive interpreter prompt
 Using a script file

Interactive interpreter prompt


 Python provides us the feature to execute the Python statement one by
one at the interactive prompt. It is preferable in the case where we are
concerned about the output of each line of our Python program.
 To open the interactive mode, open the terminal (or command
prompt) and type python .It will open the command prompt where we
can execute the Python statement and check their impact on the
console.
First Python Program

Using a script file


 Interpreter prompt is good to run the individual statements of the
code. However, we cannot write the code every-time on the
terminal.
 We need to write our code into a file which can be executed later.
For this purpose, open an editor like notepad, create a file named
first.py (Python used .py extension) and write the code in it.
First Python Program

 print ("hello world"); #here, we have used print() function to print the
message on the console.
Statements and Syntax

Comments ( # )
 Python comment statements begin with the pound sign or hash symbol
(#).
 A comment can begin anywhere on a line. All characters following the
# to the end of the line are ignored by the interpreter
Continuation ( \ )
 Python statements are, in general, delimited by NEWLINEs, meaning one
statement per line.
 Single statements can be broken up into multiple lines by use of the
backslash.
 if (a == 1) and \
(b == 0):
Print(“msg”)
Statements and Syntax
There are two exceptions where lines can be continued without backslashes.
 A single statement can take up more than one line when enclosing
operators are used, i.e., parentheses, square brackets, or braces, and when
NEWLINEs are contained in strings enclosed in triple quotes.
 # display a string with triple quotes
print '''hi there, this is a long message for you
that goes over multiple lines... you will find
out soon that triple quotes in Python allows
this kind of fun! it is like a day on the beach!'''
 # set some variables
go_surf, get_a_tan_while, boat_size, toll_money = (1,
'windsurfing', 40.0, -2.00)
Statements and Syntax
Multiple Statement Groups as Suites ( : )
 Groups of individual statements making up a single code block are
called “suites” in Python.
 Compound or complex statements, such as if, while, def, and class,
are those that require a header line and a suite.
 Header lines begin the statement (with the keyword) and terminate
with a colon ( : ) and are followed by one or more lines that make
up the suite.
Statements and Syntax
Suites Delimited via Indentation
 Python employs indentation as a means of delimiting blocks of code.
Code at inner levels are indented via spaces or tabs.
 Indentation requires exact indentation; in other words, all the lines of
code in a suite must be indented at the exact same level (e.g., same
number of spaces).
 if (a == 1) and (b == 0):
c= a+b
Print(“msg”)

Multiple Statements on a Single Line ( ; )


 The semicolon ( ; ) allows multiple statements on a single line given that
neither statement starts a new code block
 import sys; x = 5; sys.stdout.write(x + '\n')

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy