Introduction to Python Programming: Syntax, Variables, Data Types, and More, Slides of Programming Languages

this ppt contains basic python programming notes

Typology: Slides

2019/2020

Uploaded on 11/02/2020

aisa-gupta
aisa-gupta 🇮🇳

4.5

(2)

3 documents

1 / 34

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Python
Programming
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22

Partial preview of the text

Download Introduction to Python Programming: Syntax, Variables, Data Types, and More and more Slides Programming Languages in PDF only on Docsity!

Python

Programming

Content

  • (^) What is Python?
  • What can Python do?
  • Why Python?
  • Python Syntax compared to other programming languages
  • Python Install
  • Indentation
  • Comments
  • Basic Syntax
  • Variable Types
  • Basic Operators
  • Decision Making
  • Loops
  • (^) Data Types
  • Function
  • Modules
  • Files
  • Tkinter

What can Python do?

  • (^) Python can be used on a server to create web applications.
  • Python can be used alongside software to create workflows.
  • Python can connect to database systems. It can also read and
modify files.
  • Python can be used to handle big data and perform complex
mathematics.
  • Python can be used for rapid prototyping, or for production-ready
software development.

Why Python?

  • Python works on different platforms (Windows, Mac, Linux, Raspberry Pi,
etc).
  • Python has a simple syntax similar to the English language.
  • Python has syntax that allows developers to write programs with fewer
lines than some other programming languages.
  • Python runs on an interpreter system, meaning that code can be executed
as soon as it is written. This means that prototyping can be very quick.
  • Python can be treated in a procedural way, an object-oriented way or a
functional way.

Python Install

Before we start Python programming, we need to have an interpreter to interpret and run our programs. There are certain online interpreters like https://ide.geeksforgeeks.org/, http://ideone.com/ or http://codepad.org/ that can be used to run Python programs without installing an interpreter.

  • 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/.

Syntax

  • Python syntax can be executed by writing directly in the

Command Line:

>>> print("Hello, World!")

Hello, World!

  • Or by creating a python file on the server, using the .py file

extension, and running it in the Command Line:

C:\Users\ Your Name >python myfile.py

Comments

  • Comments can be used to explain Python code.
  • Comments can be used to make the code more readable.
  • Comments can be used to prevent execution when testing

code.

Example

#This is a comment

print("Hello, World!")

Variable

  • Variables are containers for storing data values.
  • Unlike other programming languages, Python has no command for declaring a variable.
  • (^) A variable is created the moment you first assign a value to it. A variable can have a short name (like x and y) or a more descriptive name (age, car name, total volume). Rules for Python variables:
  • (^) A variable name must start with a letter or the underscore character
  • A variable name cannot start with a number
  • A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
  • Variable names are case-sensitive (age, Age and AGE are three different variables)
  • Example #Legal variable names: myvar = "John" my_var = "John" _my_var = "John"

Decision Making

Python programming language assumes any non-zero and non-null values as TRUE, and if it is either zero or null , then it is assumed as FALSE value. Python programming language provides following types of decision making statements:

  • if: can use one or more loop inside any another while, for or do..while loop. Syntax if expression: statement(s)
  • (^) if…else: An if statement can be followed by an optional else statement , which executes when the boolean expression is FALSE. Syntax if expression: statement(s) else: statement(s)
  • Nested if: can use one if or else if statement inside another if or else if statement(s). Syntax if expression1: statement(s) elif expression3: statement(s) else: statement(s)

Loop Control Statements

  • Loop control statements change execution from its normal sequence. When execution
leaves a scope, all automatic objects that were created in that scope are destroyed.
Python supports the following control statements:
  • break: Terminates the loop statement and transfers execution to the statement
immediately following the loop.
  • continue: Causes the loop to skip the remainder of its body and immediately retest its
condition prior to reiterating.
  • pass: The pass statement in Python is used when a statement is required syntactically
but you do not want any command or code to execute

Data Types

  • Variables can store data of different types, and different types can do different things. Python has the following data types built-in by default, in these categories:

String

  • (^) Strings are arrays of bytes representing Unicode characters. A

string is a collection of one or more characters put in a single

quote, double-quote or triple quote.

  • (^) There is no character data type, a character is a string of

length one. It is represented by str class.

  • (^) Individual characters of a String can be accessed by using the

method of Indexing.