PYTHON PROGRAMMING
WHAT IS PYTHON? • Python is a popular programming language. It was created by Guido van Rossum, and released in 1991. • It is used for: ➢Web Development (Server-side) ➢Software Development ➢Mathematics ➢System Scripting.
WHAT CAN PYTHON DO? a) Python can be used on a server to create web applications. b) Python can be used alongside software to create workflows. c) Python can connect to database systems. It can also read and modify files. d) Python can be used to handle big data and perform complex mathematics. e) Python can be used for rapid prototyping, or for production-ready software development.
WHY PYTHON? • Python works on different platforms. • It has a simple syntax similar to the English language. • Its syntax allows developers to write programs with fewer lines. • It runs on an interpreter system, meaning that code can be executed as soon as it is written. • It can be treated in a procedural way, an object-oriented way or a functional way.
PYTHON SYNTAX COMPARED TO OTHER PROGRAMMING LANGUAGES • Python was designed for readability, and has some similarities to the English language with influence from mathematics. • Python uses new lines to complete a command, as opposed to other programming languages which often use semicolons or parentheses. • Python relies on indentation, using whitespace, to define scope; such as the scope of loops, functions and classes. Other programming languages often use curly- brackets for this purpose.
PYTHON INSTALL • To check if you have python installed on aWindows PC, search in the start bar for Python or run the following on the Command Line (cmd.exe): • To check if you have python installed on a Linux or Mac, then on linux open the command line or on Mac open theTerminal and type: • If you find that you do not have python installed on your computer, then you can download it for free from the following website: https://www.python.org/
PYTHON INDENTATION • Indentation refers to the spaces at the beginning of a code line. • Where in other programming languages the indentation in code is for readability only, the indentation in Python is very important. • Python uses indentation to indicate a block of code. • Python will give you an error if you skip the indentation. • The number of spaces is up to you as a programmer, but it has to be at least one.
PYTHON COMMENTS • Comments starts with a #, and Python will ignore them: • A comment does not have to be text that explains the code, it can also be used to prevent Python from executing code:
PYTHON VARIABLES • In Python, variables are created when you assign a value to it. • Python has no command for declaring a variable. • Variables do not need to be declared with any particular type, and can even change type after they have been set. • Variable names are case-sensitive.
PYTHON VARIABLES (cont.) • Python allows you to assign values to multiple variables in one line: • If you have a collection of values in a list, tuple etc. Python allows you extract the values into variables.This is called unpacking.
PYTHON VARIABLES (cont.) • The Python print statement is often used to output variables. • To combine both text and a variable, Python uses the + character: • You can also use the + character to add a variable to another variable. For numbers, the + character works as a mathematical operator
PYTHON DATA TYPES • In programming, data type is an important concept.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: • You can get the data type of any object by using the type() function: Data Type Keywords Text: str Numeric: int, float, complex Sequence: list, tuple, range Mapping: dict Set: set, frozenset Boolean: bool Binary: bytes, bytearray, memoryview
Python Programming.pdf

Python Programming.pdf

  • 1.
  • 2.
    WHAT IS PYTHON? •Python is a popular programming language. It was created by Guido van Rossum, and released in 1991. • It is used for: ➢Web Development (Server-side) ➢Software Development ➢Mathematics ➢System Scripting.
  • 3.
    WHAT CAN PYTHONDO? a) Python can be used on a server to create web applications. b) Python can be used alongside software to create workflows. c) Python can connect to database systems. It can also read and modify files. d) Python can be used to handle big data and perform complex mathematics. e) Python can be used for rapid prototyping, or for production-ready software development.
  • 4.
    WHY PYTHON? • Pythonworks on different platforms. • It has a simple syntax similar to the English language. • Its syntax allows developers to write programs with fewer lines. • It runs on an interpreter system, meaning that code can be executed as soon as it is written. • It can be treated in a procedural way, an object-oriented way or a functional way.
  • 5.
    PYTHON SYNTAX COMPAREDTO OTHER PROGRAMMING LANGUAGES • Python was designed for readability, and has some similarities to the English language with influence from mathematics. • Python uses new lines to complete a command, as opposed to other programming languages which often use semicolons or parentheses. • Python relies on indentation, using whitespace, to define scope; such as the scope of loops, functions and classes. Other programming languages often use curly- brackets for this purpose.
  • 6.
    PYTHON INSTALL • Tocheck if you have python installed on aWindows PC, search in the start bar for Python or run the following on the Command Line (cmd.exe): • To check if you have python installed on a Linux or Mac, then on linux open the command line or on Mac open theTerminal and type: • If you find that you do not have python installed on your computer, then you can download it for free from the following website: https://www.python.org/
  • 7.
    PYTHON INDENTATION • Indentationrefers to the spaces at the beginning of a code line. • Where in other programming languages the indentation in code is for readability only, the indentation in Python is very important. • Python uses indentation to indicate a block of code. • Python will give you an error if you skip the indentation. • The number of spaces is up to you as a programmer, but it has to be at least one.
  • 8.
    PYTHON COMMENTS • Commentsstarts with a #, and Python will ignore them: • A comment does not have to be text that explains the code, it can also be used to prevent Python from executing code:
  • 9.
    PYTHON VARIABLES • InPython, variables are created when you assign a value to it. • Python has no command for declaring a variable. • Variables do not need to be declared with any particular type, and can even change type after they have been set. • Variable names are case-sensitive.
  • 10.
    PYTHON VARIABLES (cont.) •Python allows you to assign values to multiple variables in one line: • If you have a collection of values in a list, tuple etc. Python allows you extract the values into variables.This is called unpacking.
  • 11.
    PYTHON VARIABLES (cont.) •The Python print statement is often used to output variables. • To combine both text and a variable, Python uses the + character: • You can also use the + character to add a variable to another variable. For numbers, the + character works as a mathematical operator
  • 12.
    PYTHON DATA TYPES •In programming, data type is an important concept.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: • You can get the data type of any object by using the type() function: Data Type Keywords Text: str Numeric: int, float, complex Sequence: list, tuple, range Mapping: dict Set: set, frozenset Boolean: bool Binary: bytes, bytearray, memoryview