The document provides an introduction to Python programming. It discusses key concepts like variables, data types, operators, and sequential data types. Python is presented as an interpreted programming language that uses indentation to indicate blocks of code. Comments and documentation are included to explain the code. Various data types are covered, including numbers, strings, booleans, and lists. Operators for arithmetic, comparison, assignment and more are also summarized.
https://www.dmdiploma.com/studymaterial?id=5/python-for-data-science
This Python course provides a beginner-friendly introduction to Python for Data Science.
This presentation covers a detailed overview of python advanced concepts. it covers the below aspects.
Comprehensions
Lambda with (map, filter and reduce)
Context managers
Iterator, Generators, Decorators
Python GIL and multiprocessing and multithreading
Python WSGI
Python Unittests
The document provides an overview of the Python programming language. It discusses what Python is, its history and naming, features like being dynamically typed and interpreted, popular applications like web development, machine learning, and its architecture. It also covers Python constructs like variables, data types, operators, and strings. The document compares Python to other languages and provides examples of common Python concepts.
Operators and Control Statements in PythonRajeswariA8
This document discusses operators and conditional statements in Python programming. It defines operators as symbols that instruct the computer to perform tasks on operands or values. The main types of operators covered are arithmetic, comparison, assignment, logical, bitwise, membership and identity operators. Conditional statements like if, else if and else are described as ways to control program flow based on conditions. Examples of using different operators and conditional statements are provided.
This document provides information on Python code structures, including if/else statements, loops (while and for), functions, and arguments. It explains the basic syntax and usage of these structures. Key points covered include:
- How to write if/else statements and the use of conditions like ==, !=, <, >, etc.
- The syntax of while and for loops, and how to use break, continue, else blocks
- What functions are in Python and how to define them with def, pass arguments, and return values
- The basics of calling functions, optional arguments, and nested structures like if/else in loops
1. Python can be used to automate repetitive tasks like data entry, file processing, report generation etc. This saves time and reduces human errors.
2. Python has many libraries for machine learning, data analysis and visualization which can be used to analyze patent data, identify trends, cluster similar technologies etc.
3. Web scraping and web development frameworks like Django can be used to build internal tools and dashboards to manage workflows more efficiently.
4. Python scripts can be written to extract and process data from various sources, perform calculations, format reports in a standardized way reducing manual efforts.
This document provides an introduction to the Python programming language. It describes Python as a multi-purpose, object-oriented language that is interpreted, dynamically typed and focuses on readability. It lists several major organizations that use Python. It then provides examples of basic Python programs and covers key Python concepts like variables, data types, strings, comments, functions and more in under 3 sentences each.
This document provides an introduction to the Python programming language. It covers Python's background, syntax, types, operators, control flow, functions, classes, tools, and IDEs. Key points include that Python is a multi-purpose, object-oriented language that is interpreted, strongly and dynamically typed. It focuses on readability and has a huge library of modules. Popular Python IDEs include Emacs, Vim, Komodo, PyCharm, and Eclipse.
The document discusses dictionaries in Python. It explains that dictionaries are a mapping type that store key-value pairs, with keys being immutable types and values being any type. It provides examples of creating, accessing, updating, removing entries from, and accessing properties of dictionaries. It also covers functions, control flow statements like if/else and while loops, and list comprehensions.
Machine Learning With Python From India’s Most Advanced Learner’s Community. 200+ High-Quality Lectures. 4 Months Live Mentor-ship. 15+ Projects. Industry Insights.
Visit- https://insideaiml.com/course-details/Machine-Learning-with-Python-Statistics
Basics of Iterators and Generators,Uses of iterators and generators in python. advantage of iterators and generators. difference between generators and iterators.
This document provides an introduction to the Python language and discusses Python data types. It covers how to install Python, interact with the Python interpreter through command line and IDLE modes, and learn basic Python parts like data types, operators, functions, and control structures. The document discusses numeric, string, and other data types in Python and how to manipulate them using built-in functions and operators. It also introduces Python library modules and the arcpy package for geoprocessing in ArcGIS.
Python is a versatile, object-oriented programming language that can be used for web development, data analysis, and more. It has a simple syntax and is easy to read and learn. Key features include being interpreted, dynamically typed, supporting functional and object-oriented programming. Common data types include numbers, strings, lists, dictionaries, tuples, and files. Functions and classes can be defined to organize and reuse code. Regular expressions provide powerful string manipulation. Python has a large standard library and is used widely in areas like GUIs, web scripting, AI, and scientific computing.
Python is an interpreted, general-purpose, high-level programming language. It allows programmers to define functions for reusing code and scoping variables within functions. Key concepts covered include objects, expressions, conditionals, loops, modules, files, and recursion. Functions can call other functions, allowing for modular and reusable code.
The document provides an introduction to programming in Python. It discusses how Python can be used for web development, desktop applications, data science, machine learning, and more. It also covers executing Python programs, reading keyboard input, decision making and loops in Python, standard data types like numbers, strings, lists, tuples and dictionaries. Additionally, it describes functions, opening and reading/writing files, regular expressions, and provides examples of SQLite database connections in Python projects.
The document introduces Python modules and importing. It discusses three formats for importing modules: import somefile, from somefile import *, and from somefile import className. It describes commonly used Python modules like sys, os, and math. It also covers defining your own modules, directories for module files, object-oriented programming in Python including defining classes, creating and deleting instances, methods and self, accessing attributes and methods, attributes, inheritance, and redefining methods.
This document provides an introduction and overview of the Python programming language. It discusses Python's origins, philosophy, features, and uses. Key points covered include Python's simplicity, power, object-oriented approach, and wide portability. Examples are provided of basic Python syntax and constructs like strings, lists, functions, modules, and dictionaries.
Here are the answers to the exercises:
1. The len() method is used to find the length of a string.
2. To get the first character of the string txt, it would be:
txt="hello"
x=txt[0]
3. The strip() method removes any whitespace from the beginning or the end of a string.
A program is a sequence of instructions that are run by the processor. To run a program, it must be compiled into binary code and given to the operating system. The OS then gives the code to the processor to execute. Functions allow code to be reused by defining operations and optionally returning values. Strings are sequences of characters that can be manipulated using indexes and methods. Common string methods include upper() and concatenation using +.
Python was created in the late 1980s by Guido van Rossum and first released in 1991. It gained popularity and saw new releases in 2000 and 2008. Python is an open source, general purpose, interpreted, object-oriented programming language used widely for web development, science, and more due to its large community and support. Performance depends more on frameworks and architecture than language alone.
This Presentation is a draft of a summary of "Learn Python The Hard Way" Book which is very helpful for anyone want to learn python from scratch of
For reading the book and do exercises, the book is available for free here: http://learnpythonthehardway.org/book/
The document provides an overview of the Python programming language. It discusses Python's history, how to install and run Python, basic data types like integers, floats, strings, lists and tuples. It explains key Python concepts like variable assignment, conditional statements, functions, modules and packages. The document also compares mutable lists and immutable tuples, and covers common list operations.
1. Python can be used to automate repetitive tasks like data entry, file processing, report generation etc. This saves time and reduces human errors.
2. Python has many libraries for machine learning, data analysis and visualization which can be used to analyze patent data, identify trends, cluster similar technologies etc.
3. Web scraping and web development frameworks like Django can be used to build internal tools and dashboards to manage workflows more efficiently.
4. Python scripts can be written to extract and process data from various sources, perform calculations, format reports in a standardized way reducing manual efforts.
This document provides an introduction to the Python programming language. It describes Python as a multi-purpose, object-oriented language that is interpreted, dynamically typed and focuses on readability. It lists several major organizations that use Python. It then provides examples of basic Python programs and covers key Python concepts like variables, data types, strings, comments, functions and more in under 3 sentences each.
This document provides an introduction to the Python programming language. It covers Python's background, syntax, types, operators, control flow, functions, classes, tools, and IDEs. Key points include that Python is a multi-purpose, object-oriented language that is interpreted, strongly and dynamically typed. It focuses on readability and has a huge library of modules. Popular Python IDEs include Emacs, Vim, Komodo, PyCharm, and Eclipse.
The document discusses dictionaries in Python. It explains that dictionaries are a mapping type that store key-value pairs, with keys being immutable types and values being any type. It provides examples of creating, accessing, updating, removing entries from, and accessing properties of dictionaries. It also covers functions, control flow statements like if/else and while loops, and list comprehensions.
Machine Learning With Python From India’s Most Advanced Learner’s Community. 200+ High-Quality Lectures. 4 Months Live Mentor-ship. 15+ Projects. Industry Insights.
Visit- https://insideaiml.com/course-details/Machine-Learning-with-Python-Statistics
Basics of Iterators and Generators,Uses of iterators and generators in python. advantage of iterators and generators. difference between generators and iterators.
This document provides an introduction to the Python language and discusses Python data types. It covers how to install Python, interact with the Python interpreter through command line and IDLE modes, and learn basic Python parts like data types, operators, functions, and control structures. The document discusses numeric, string, and other data types in Python and how to manipulate them using built-in functions and operators. It also introduces Python library modules and the arcpy package for geoprocessing in ArcGIS.
Python is a versatile, object-oriented programming language that can be used for web development, data analysis, and more. It has a simple syntax and is easy to read and learn. Key features include being interpreted, dynamically typed, supporting functional and object-oriented programming. Common data types include numbers, strings, lists, dictionaries, tuples, and files. Functions and classes can be defined to organize and reuse code. Regular expressions provide powerful string manipulation. Python has a large standard library and is used widely in areas like GUIs, web scripting, AI, and scientific computing.
Python is an interpreted, general-purpose, high-level programming language. It allows programmers to define functions for reusing code and scoping variables within functions. Key concepts covered include objects, expressions, conditionals, loops, modules, files, and recursion. Functions can call other functions, allowing for modular and reusable code.
The document provides an introduction to programming in Python. It discusses how Python can be used for web development, desktop applications, data science, machine learning, and more. It also covers executing Python programs, reading keyboard input, decision making and loops in Python, standard data types like numbers, strings, lists, tuples and dictionaries. Additionally, it describes functions, opening and reading/writing files, regular expressions, and provides examples of SQLite database connections in Python projects.
The document introduces Python modules and importing. It discusses three formats for importing modules: import somefile, from somefile import *, and from somefile import className. It describes commonly used Python modules like sys, os, and math. It also covers defining your own modules, directories for module files, object-oriented programming in Python including defining classes, creating and deleting instances, methods and self, accessing attributes and methods, attributes, inheritance, and redefining methods.
This document provides an introduction and overview of the Python programming language. It discusses Python's origins, philosophy, features, and uses. Key points covered include Python's simplicity, power, object-oriented approach, and wide portability. Examples are provided of basic Python syntax and constructs like strings, lists, functions, modules, and dictionaries.
Here are the answers to the exercises:
1. The len() method is used to find the length of a string.
2. To get the first character of the string txt, it would be:
txt="hello"
x=txt[0]
3. The strip() method removes any whitespace from the beginning or the end of a string.
A program is a sequence of instructions that are run by the processor. To run a program, it must be compiled into binary code and given to the operating system. The OS then gives the code to the processor to execute. Functions allow code to be reused by defining operations and optionally returning values. Strings are sequences of characters that can be manipulated using indexes and methods. Common string methods include upper() and concatenation using +.
Python was created in the late 1980s by Guido van Rossum and first released in 1991. It gained popularity and saw new releases in 2000 and 2008. Python is an open source, general purpose, interpreted, object-oriented programming language used widely for web development, science, and more due to its large community and support. Performance depends more on frameworks and architecture than language alone.
This Presentation is a draft of a summary of "Learn Python The Hard Way" Book which is very helpful for anyone want to learn python from scratch of
For reading the book and do exercises, the book is available for free here: http://learnpythonthehardway.org/book/
The document provides an overview of the Python programming language. It discusses Python's history, how to install and run Python, basic data types like integers, floats, strings, lists and tuples. It explains key Python concepts like variable assignment, conditional statements, functions, modules and packages. The document also compares mutable lists and immutable tuples, and covers common list operations.
This document provides an overview of learning Python in three hours. It covers Python's history, installing and running Python, basic data types like integers, floats and strings. It also discusses sequence types like lists, tuples and strings, and how lists are mutable while tuples are immutable. The document includes examples of basic syntax like assignment, conditionals, functions and modules. It provides guidance on naming conventions and discusses the Python interpreter, editors and development environments.
This document provides an overview of the Python programming language. It discusses Python's history and key features such as being an interpreted, object-oriented, and functional language. The document also covers installing Python, running Python scripts and programs, basic datatypes like integers and strings, sequence types like lists and tuples, and other basic concepts like functions, variables, and flow control.
The document provides an overview of the Python programming language. It discusses Python's history, how to install and run Python, basic data types like integers, floats, strings, lists and tuples. It explains key concepts like variable assignment, conditional statements, functions, modules and packages. The document also compares mutable lists and immutable tuples, and covers common list operations.
The document provides an overview of the Python programming language. It discusses Python's history, how to install and run Python, basic data types like integers, floats, strings, lists and tuples. It explains key concepts like variable assignment, basic operations, slicing of sequences, and how lists are mutable but tuples are immutable. The document is intended to teach Python fundamentals in about three hours.
This document provides an overview of the Python programming language. It discusses Python's history and key features such as being object-oriented, scalable, and functional from the beginning. It also covers installing Python, running Python programs, basic datatypes like integers and strings, sequence types like lists and tuples, and other basic concepts like functions, comments, and whitespace.
The document provides an overview of the Python programming language. It discusses Python's history, how to install and run Python, basic data types like integers, floats, strings, lists and tuples. It explains key concepts like variable assignment, basic operations, slicing of sequences, and how lists are mutable but tuples are immutable. The document is intended to teach Python fundamentals in about three hours.
The document provides an overview of the Python programming language. It discusses Python's history, how to install and run Python, basic data types like integers, floats, strings, and lists. It also covers Python concepts like functions, modules, conditionals, loops, classes and objects.
The document provides an overview of the Python programming language. It discusses Python's history and key features such as being scalable, object oriented, and functional. It also covers installing Python, running Python programs, basic datatypes like integers and strings, sequence types like lists and tuples, and other basic concepts like functions, variables, and control flow.
The document provides an overview of the Python programming language. It discusses Python's history, how to install and run Python, basic data types like integers, floats, strings, lists and tuples. It explains key concepts like variable assignment, basic operations, slicing of sequences, and how lists are mutable but tuples are immutable. The document is intended to teach Python fundamentals in about three hours.
The document provides an overview of the Python programming language. It discusses Python's history, how to install and run Python, basic data types like integers, floats, strings, lists and tuples. It explains key concepts like variable assignment, basic operations, slicing of sequences, and how lists are mutable but tuples are immutable. The document is intended to teach Python fundamentals in about three hours.
The document provides an overview of the Python programming language. It discusses Python's history, how to install and run Python, basic data types like integers, floats, strings, lists and tuples. It explains key concepts like variable assignment, conditional statements, functions, modules and packages. The document also compares mutable lists and immutable tuples, and covers common list operations.
The document provides an overview of the Python programming language. It discusses Python's history, how to install and run Python, basic data types like integers, floats, strings, lists and tuples. It explains key concepts like variable assignment, conditional statements, functions, modules and packages. The document also compares mutable lists and immutable tuples, and covers common list operations.
This document provides an overview of the Python programming language. It discusses Python's history and key features such as being an interpreted, object-oriented, and functional language. The document also covers installing Python, running Python scripts and programs, basic datatypes like integers and strings, sequence types like lists and tuples, and other basic concepts like functions, variables, and flow control.
This document provides an overview of the Python programming language. It discusses Python's history, how to install and run Python, basic data types like integers, floats, strings, lists and tuples. It also covers topics like functions, modules, files, and classes in Python.
Fundamentals of Information Technology study MaterialBobby Murugesan
This is the study material of Fundamentals Information Technology of B.Sc Computer Science Students of Mother Teresa Women's University Kodaikanal. It covers the complete syllabus unit wise.
Computer skills for web designing and video editing_Lab Manual.pdfBobby Murugesan
The document provides code for creating various web elements using HTML tags. It includes code samples for creating definition lists, ordered and unordered lists, tables, images, hyperlinks, forms, and more. Instructions are provided for each code sample explaining how to create each element step-by-step using the appropriate HTML tags. The document serves as a manual for learning basic HTML tags and how to use them to design web pages and forms.
This document contains a table of contents and code snippets for various Python programming exercises, including finding the largest of three numbers, calculating mean, median, and mode of a list of numbers, swapping two variables, checking if a number is Armstrong, finding the square root of a number, checking if a number is odd or even, reversing a number, checking for palindromes, checking for leap years, finding the area of a triangle, counting characters in a string and storing in a dictionary, finding prime numbers, calculating length of a string, and performing basic math operations. The document provides sample input/output for each code snippet.
It shows the top most impressive google apps and its usages. Students can know about the apps developed by Google and the usage and its functionality too.
How to manage Multiple Warehouses for multiple floors in odoo point of saleCeline George
The need for multiple warehouses and effective inventory management is crucial for companies aiming to optimize their operations, enhance customer satisfaction, and maintain a competitive edge.
The ever evoilving world of science /7th class science curiosity /samyans aca...Sandeep Swamy
The Ever-Evolving World of
Science
Welcome to Grade 7 Science4not just a textbook with facts, but an invitation to
question, experiment, and explore the beautiful world we live in. From tiny cells
inside a leaf to the movement of celestial bodies, from household materials to
underground water flows, this journey will challenge your thinking and expand
your knowledge.
Notice something special about this book? The page numbers follow the playful
flight of a butterfly and a soaring paper plane! Just as these objects take flight,
learning soars when curiosity leads the way. Simple observations, like paper
planes, have inspired scientific explorations throughout history.
Odoo Inventory Rules and Routes v17 - Odoo SlidesCeline George
Odoo's inventory management system is highly flexible and powerful, allowing businesses to efficiently manage their stock operations through the use of Rules and Routes.
How to Set warnings for invoicing specific customers in odooCeline George
Odoo 16 offers a powerful platform for managing sales documents and invoicing efficiently. One of its standout features is the ability to set warnings and block messages for specific customers during the invoicing process.
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessMark Soia
Boost your chances of passing the 2V0-11.25 exam with CertsExpert reliable exam dumps. Prepare effectively and ace the VMware certification on your first try
Quality dumps. Trusted results. — Visit CertsExpert Now: https://www.certsexpert.com/2V0-11.25-pdf-questions.html
Title: A Quick and Illustrated Guide to APA Style Referencing (7th Edition)
This visual and beginner-friendly guide simplifies the APA referencing style (7th edition) for academic writing. Designed especially for commerce students and research beginners, it includes:
✅ Real examples from original research papers
✅ Color-coded diagrams for clarity
✅ Key rules for in-text citation and reference list formatting
✅ Free citation tools like Mendeley & Zotero explained
Whether you're writing a college assignment, dissertation, or academic article, this guide will help you cite your sources correctly, confidently, and consistent.
Created by: Prof. Ishika Ghosh,
Faculty.
📩 For queries or feedback: [email protected]
A measles outbreak originating in West Texas has been linked to confirmed cases in New Mexico, with additional cases reported in Oklahoma and Kansas. The current case count is 817 from Texas, New Mexico, Oklahoma, and Kansas. 97 individuals have required hospitalization, and 3 deaths, 2 children in Texas and one adult in New Mexico. These fatalities mark the first measles-related deaths in the United States since 2015 and the first pediatric measles death since 2003.
The YSPH Virtual Medical Operations Center Briefs (VMOC) were created as a service-learning project by faculty and graduate students at the Yale School of Public Health in response to the 2010 Haiti Earthquake. Each year, the VMOC Briefs are produced by students enrolled in Environmental Health Science Course 581 - Public Health Emergencies: Disaster Planning and Response. These briefs compile diverse information sources – including status reports, maps, news articles, and web content– into a single, easily digestible document that can be widely shared and used interactively. Key features of this report include:
- Comprehensive Overview: Provides situation updates, maps, relevant news, and web resources.
- Accessibility: Designed for easy reading, wide distribution, and interactive use.
- Collaboration: The “unlocked" format enables other responders to share, copy, and adapt seamlessly. The students learn by doing, quickly discovering how and where to find critical information and presenting it in an easily understood manner.
CURRENT CASE COUNT: 817 (As of 05/3/2025)
• Texas: 688 (+20)(62% of these cases are in Gaines County).
• New Mexico: 67 (+1 )(92.4% of the cases are from Eddy County)
• Oklahoma: 16 (+1)
• Kansas: 46 (32% of the cases are from Gray County)
HOSPITALIZATIONS: 97 (+2)
• Texas: 89 (+2) - This is 13.02% of all TX cases.
• New Mexico: 7 - This is 10.6% of all NM cases.
• Kansas: 1 - This is 2.7% of all KS cases.
DEATHS: 3
• Texas: 2 – This is 0.31% of all cases
• New Mexico: 1 – This is 1.54% of all cases
US NATIONAL CASE COUNT: 967 (Confirmed and suspected):
INTERNATIONAL SPREAD (As of 4/2/2025)
• Mexico – 865 (+58)
‒Chihuahua, Mexico: 844 (+58) cases, 3 hospitalizations, 1 fatality
• Canada: 1531 (+270) (This reflects Ontario's Outbreak, which began 11/24)
‒Ontario, Canada – 1243 (+223) cases, 84 hospitalizations.
• Europe: 6,814
The Pala kings were people-protectors. In fact, Gopal was elected to the throne only to end Matsya Nyaya. Bhagalpur Abhiledh states that Dharmapala imposed only fair taxes on the people. Rampala abolished the unjust taxes imposed by Bhima. The Pala rulers were lovers of learning. Vikramshila University was established by Dharmapala. He opened 50 other learning centers. A famous Buddhist scholar named Haribhadra was to be present in his court. Devpala appointed another Buddhist scholar named Veerdeva as the vice president of Nalanda Vihar. Among other scholars of this period, Sandhyakar Nandi, Chakrapani Dutta and Vajradatta are especially famous. Sandhyakar Nandi wrote the famous poem of this period 'Ramcharit'.
A measles outbreak originating in West Texas has been linked to confirmed cases in New Mexico, with additional cases reported in Oklahoma and Kansas. The current case count is 795 from Texas, New Mexico, Oklahoma, and Kansas. 95 individuals have required hospitalization, and 3 deaths, 2 children in Texas and one adult in New Mexico. These fatalities mark the first measles-related deaths in the United States since 2015 and the first pediatric measles death since 2003.
The YSPH Virtual Medical Operations Center Briefs (VMOC) were created as a service-learning project by faculty and graduate students at the Yale School of Public Health in response to the 2010 Haiti Earthquake. Each year, the VMOC Briefs are produced by students enrolled in Environmental Health Science Course 581 - Public Health Emergencies: Disaster Planning and Response. These briefs compile diverse information sources – including status reports, maps, news articles, and web content– into a single, easily digestible document that can be widely shared and used interactively. Key features of this report include:
- Comprehensive Overview: Provides situation updates, maps, relevant news, and web resources.
- Accessibility: Designed for easy reading, wide distribution, and interactive use.
- Collaboration: The “unlocked" format enables other responders to share, copy, and adapt seamlessly. The students learn by doing, quickly discovering how and where to find critical information and presenting it in an easily understood manner.
P-glycoprotein pamphlet: iteration 4 of 4 finalbs22n2s
Python The basics
1. Python - The Basics
M.BOBBY
ASSISTANT PROFESSOR & HEAD,
DEPARTMENT OF COMPUTER SCIENCE
SRI ADI CHUNCHANAGIRI WOMEN’S COLLEGE, CUMBUM
2. A Code Sample (in IDLE)
x = 34 - 23 # A comment.
y = “Hello” # Another one.
z = 3.45
if z == 3.45 or y == “Hello”:
x = x + 1
y = y + “ World” # String concat.
print x
print y
3. Enough to Understand the Code
• Indentation matters to code meaning
• Block structure indicated by indentation
• First assignment to a variable creates it
• Variable types don’t need to be declared.
• Python figures out the variable types on its own.
• Assignment is = and comparison is ==
• For numbers + - * / % are as expected
• Special use of + for string concatenation and % for string formatting (as in C’s
printf)
• Logical operators are words (and, or, not) not symbols
• The basic printing command is print
4. Basic Datatypes
• Integers (default for numbers)
z = 5 / 2 # Answer 2, integer division
• Floats
x = 3.456
• Strings
• Can use “” or ‘’ to specify with “abc” == ‘abc’
• Unmatched can occur within the string: “matt’s”
• Use triple double-quotes for multi-line strings or strings than contain
both ‘ and “ inside of them:
“““a‘b“c”””
5. Whitespace
Whitespace is meaningful in Python: especially indentation and placement of
newlines
•Use a newline to end a line of code
Use when must go to next line prematurely
•No braces {} to mark blocks of code, use consistent indentation instead
• First line with less indentation is outside of the block
• First line with more indentation starts a nested block
•Colons start of a new block in many constructs, e.g. function definitions, then
clauses
6. Comments
• Start comments with #, rest of line is ignored
• Can include a “documentation string” as the first line of a new function or class
you define
• Development environments, debugger, and other tools use it: it’s good style to
include one
def fact(n):
“““fact(n) assumes n is a positive integer and returns
facorial of n.”””
assert(n>0)
return 1 if n==1 else n*fact(n-1)
7. Assignment
• Binding a variable in Python means setting a name to hold a reference to some object
• Assignment creates references, not copies
• Names in Python do not have an intrinsic type, objects have types
• Python determines the type of the reference automatically based on what data is assigned to it
• You create a name the first time it appears on the left side of an assignment expression:
x = 3
• A reference is deleted via garbage collection after any names bound to it have passed out of scope
• Python uses reference semantics (more later)
8. Naming Rules
• Names are case sensitive and cannot start with a number. They can contain
letters, numbers, and underscores.
bob Bob _bob _2_bob_ bob_2 BoB
• There are some reserved words:
and, assert, break, class, continue, def, del, elif,
else, except, exec, finally, for, from, global, if,
import, in, is, lambda, not, or, pass, print, raise,
return, try, while
9. Naming conventions
The Python community has these recommend-ed naming conventions
•joined_lower for functions, methods and, attributes
•joined_lower or ALL_CAPS for constants
•StudlyCaps for classes
•camelCase only to conform to pre-existing conventions
•Attributes: interface, _internal, __private
10. Assignment
• You can assign to multiple names at the same time
>>> x, y = 2, 3
>>> x
2
>>> y
3
This makes it easy to swap values
>>> x, y = y, x
• Assignments can be chained
>>> a = b = x = 2
11. Accessing Non-Existent Name
Accessing a name before it’s been properly created (by placing it on the left side of an assignment),
raises an error
>>> y
Traceback (most recent call last):
File "<pyshell#16>", line 1, in -toplevel-
y
NameError: name ‘y' is not defined
>>> y = 3
>>> y
3