Python Course PDF
Document Details
Uploaded by WonderfulAtlanta
Tanta University
Tags
Summary
This document is a Python course that includes information on syntax, variables, data types and more. It is presented as a slideshow with examples of Python code and explanations of different concepts.
Full Transcript
PYTHON COURSE sec4: Syntax , variables & data type SY N TA X O F P Y T H O N : Syntax: the set of rules and structures for writing code (grammar) Python Indentation: (the basis of PY syntax) Refers to the spaces at the beginning of a code line Used to Indicate a block of co...
PYTHON COURSE sec4: Syntax , variables & data type SY N TA X O F P Y T H O N : Syntax: the set of rules and structures for writing code (grammar) Python Indentation: (the basis of PY syntax) Refers to the spaces at the beginning of a code line Used to Indicate a block of code ,Instead of curly braces {} like in many other programming languages, Python relies on indentation (whitespace) to determine the beginning and end of code blocks. Used for: functions, loops, conditionals, and classes. D I F F B E T W E E N SY N TA X & S E M A N T I C S E R R O R Syntax Error: Structural (grammar or language rules) Semantic Error: Logical (meaning or intent) D ATA T Y P E S : Data types: the classification or categorization of data items Python is a dynamic data type type options Text string Numeric Int , float, complex Boolean Bool none noneType Sequence list , tuple, range VARIABLES: Variables : containers for storing data values Creating a variable: Python has no command for declaring a variable A variable is created the moment you first assign a value to it Declaring a Var in PY: assign a value to it CONTINUE… Get the type: By using function type() variables name: 1. A variable name can only contain (A z, 0 9 , and _) alpha, numeric characters and underscores 2. A variable name cannot start with a number 3. A variable name cannot be any of the Python keywords. Variable names are case-sensitive (a != A) CONTINUE… assign multi value: Make sure the number of variables matches the number of values, or else you will get an error. Or you can assign the same value to multiple variables in one line N U M E R I C D ATA T Y P E : There are three numeric types in Python: 1. int 2. float 3. complex Complex: Numbers that have both a real and an imaginary part, represented as a + bj where a is the real part , b is the imaginary part & j is the imaginary unit CASTING: Casting in Python: used to convert one data type to another. This is useful when you want to perform operations on data that require a specific type Str casting: Int casting: Float casting: IN PUT & OUTPUT: Input: to interact with user use input( ) function Output to display the output use print( ) function COMMENTS: (# ) For single line comment (””” ””” / ’’’ ’’’) for multi line comment THANK YOU!