0% found this document useful (0 votes)
2 views35 pages

Unit 1 Python Notes

This document provides an introduction to Python, detailing its uses in web development, software development, machine learning, and more. It highlights Python's simplicity, readability, and cross-platform capabilities, along with installation instructions and basic syntax rules. Additionally, it covers Python variables, keywords, and the importance of indentation in code structure.

Uploaded by

ayshahnr0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
2 views35 pages

Unit 1 Python Notes

This document provides an introduction to Python, detailing its uses in web development, software development, machine learning, and more. It highlights Python's simplicity, readability, and cross-platform capabilities, along with installation instructions and basic syntax rules. Additionally, it covers Python variables, keywords, and the importance of indentation in code structure.

Uploaded by

ayshahnr0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 35
27-03-2025 Unit-1 Introduction to Python Presented By: Hassan N 27-03-2025 Introduction to Python 2 Marks What is Python? + Python is a popular programming language. It was created by Guido van Rossum, and released in 1991. + Itis used for: *+ web development (server-side), + software development, Machine Lerning, Automation, Artificial intelligence etc + mathematics, + system scripting ‘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. Introduction to Python 2 Marks 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. 27-03-2025 Tatroduction to Python 2 Marks Good to know ¥ The most recent major version of Python is Python 3, which we shall be using now. However, Python 2, although not being updated with anything other than security updates, is still quite popular. ¥ In this Python will be written in a text editor. It is possible to write Python in an Integrated Development Environment(IDE), such as Thonny, Pycharm, Netbeans Eclipse or VS code which are particularly useful when managing larger collections of Python files. 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 2 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. Tntroduction t2 Marks Python Install + Many PCs and Macs will have python already installed. + To check if you have python installed on a Windows PC, search in the start bar for Python or run the following on the Command Line (cmd.exe): \Users\Your Name>python —version + To check if you have python installed on a Linux or Mac, then on linux open the ‘command line or on Mac open the Terminal and type: python -version Note: if you find that you do not have Python installed on your computer, then you can download it for free from the following website: httos://www.python.or Python Quickstart Python is an interpreted programming language, this means that as a developer you write Python (.py) files in a text editor and then put those files into the python, interpreter to be executed The way to run a python file is like this on the command line: C:\Users\Your Name>python helloworld.py, 27-03-2025 Tatroduction t2 Marks: Python Quickstart Python is an interpreted programming language, this means that as a developer you write Python (.py) files in a text editor and then put those files into the python interpreter to be executed The way to run a python file is like this on the command line: :\Users\Your Name>python helloworld.py The Python Command Line To test a short amount of code in python sometimes it is quickest and easiest not to write the code in a file, This is made possible because Python can be run as a command line itself. Type the following on the Windows, Mac or Linux command lin :\Users\Your Name>python r, if the "python" command did not work, you can try "py":C:\Users\Your Name>py From there you can write any python, including our hello world example. Tatroduction 2 Marks Python Quickstart Hello, Whenever you are done in the python command line, you can simply type the following to quit the python command line interface: 27-03-2025 Tatroduction 2 Marks Python Syntax: fxecute Python Syntax 'As we learned inthe previous pag, Python syrtax can be executed by writing srety inthe Command Line >>> print("Hello, World!") Helo, World! Or by creating python fie onthe server, using the py le extension, and running tin the Command tine: C:\Users\Your Name>python myfile.py_ Python Indentation: Indentation refers tothe 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. ES Python will give you an error if you skip the indentation ‘syntax Error: Tatroduction 2 Marks 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. ‘The number of spaces is up to you as a programmer, the most common use is four, but it has to be at least Example Prine("Five 42 greater than tio!”) print("Five is greater than te Python Variables In Python, variables are created when you assign a value to it Example: x=5 y= "Hello, World!” Python has no command for declaring a variables. sony 27-03-2025 Python Keywords: 2marks Aug 2023 = Keywords are reserve words, they have their own fixed meaning these meanings are not changed by the programmers at any circumstance. All python keyword must be write in small case letters = Example of python keywords: del, clear, def, list, tuple, set, dict, bool, int, float, str, etc Python Variables/Identifiers: 2 marks Aug 2023 * Variables are containers for storing data values. * Variables are the name given by the programmer to identify the programming elements such as array name, list name, tuple name, set name, dictionary name, class name and function name etc. variables are also called as an identifiers. The variable name may be in upper case or lower case letters. = Example of variables: a, b, sum, add, roll_no, total_num, etc Python Variables/Identifiers: 2 marks Aug 2023 * Variables are containers for storing data values. = Variables are the name given by the programmer to identify the programming elements such as array name, list name, tuple name, set name, dictionary name, class name and function name etc. variables are also called as an identifiers. The variable name may be in upper case or lower case letters. Creating Variables Python has no command for declaring a variable. Avariable is created the moment you first assign a value to it. Example: Output 5 John print) printy) Note: Variables do not need to be declared with any particular type, and can even change type after they have been set x=4 xis of type int X= "Salary" ##x is now of type str print) Output: Salary. 27-03-2025 Python Variables: Casting: If you want to specify the data type of a variable, this can be done with castinng. Ex: str(3)_ # x will be '3" y=int(3) #ywill be3 2 float(3) #z will be 3.0 Get the Type You can get the data type of a variable with the type() function. Ex: x=5 print(type(x)) print(type(y)) Note : We will learn more about data types and casting later. Single or Double Quotes? String variables can be declared either by using single or double quotes: x="John* is the same as, “John' Python Variables: Case-Sensitive: Variable names are case-sensitive, Ex This will create two variables: a A Rules for Python - Variable Names: ‘A variable can have a short name (ike x and y) or a more descriptive name (age, carname, total_volume). Rules for Python variables: ‘variable name must start with a letter or the underscore character ‘variable name cannot start with a number ‘variable name can only contain alpha-numeric characters and underscores (A-2, 0-9, and _) Variable names are case-sensitive (age, Age and AGE are three different variables) ‘variable name cannot be any of the Python keywords. ally" HA will not overwrite a

You might also like