Python language: Basics
|
|
- Easter Wells
- 5 years ago
- Views:
Transcription
1 Python language: Basics The FOSSEE Group Department of Aerospace Engineering IIT Bombay Mumbai, India FOSSEE Team (FOSSEE IITB) Basic Python 1 / 45
2 Outline 1 Data types Numbers Booleans Strings 2 Operators 3 Simple IO FOSSEE Team (FOSSEE IITB) Basic Python 2 / 45
3 Outline Data types 1 Data types Numbers Booleans Strings 2 Operators 3 Simple IO FOSSEE Team (FOSSEE IITB) Basic Python 3 / 45
4 Data types Primitive Data types Numbers: float, int, complex Strings Booleans FOSSEE Team (FOSSEE IITB) Basic Python 4 / 45
5 Outline Data types Numbers 1 Data types Numbers Booleans Strings 2 Operators 3 Simple IO FOSSEE Team (FOSSEE IITB) Basic Python 5 / 45
6 Numbers Data types Numbers int whole number, no matter what the size! In []: a = 13 In []: b = float In []: p = complex In []: c = 3+4j In []: c = complex(3, 4) FOSSEE Team (FOSSEE IITB) Basic Python 6 / 45
7 Outline Data types Booleans 1 Data types Numbers Booleans Strings 2 Operators 3 Simple IO FOSSEE Team (FOSSEE IITB) Basic Python 7 / 45
8 Booleans Data types Booleans In []: t = True In []: F = not t In []: F or t Out[]: True In []: F and t Out[]: False FOSSEE Team (FOSSEE IITB) Basic Python 8 / 45
9 Data types ( ) for precedence Booleans In []: a = False In []: b = True In []: c = True In []: (a and b) or c Out[]: True In []: a and (b or c) Out[]: False FOSSEE Team (FOSSEE IITB) Basic Python 9 / 45
10 Outline Data types Strings 1 Data types Numbers Booleans Strings 2 Operators 3 Simple IO FOSSEE Team (FOSSEE IITB) Basic Python 10 / 45
11 Strings Data types Strings Anything within quotes is a string! This is a string " This too! " """ This one too! """ And one more! FOSSEE Team (FOSSEE IITB) Basic Python 11 / 45
12 Strings Data types Strings Why so many? "Do or do not. No try." said Yoda. " is a mighty lonely quote." The triple quoted ones can span multiple lines! """ The quick brown fox jumped over the lazy dingbat. """ FOSSEE Team (FOSSEE IITB) Basic Python 12 / 45
13 Strings Data types Strings In []: w = "hello" In []: print(w[0], w[1], w[-1]) In []: len(w) Out[]: 5 FOSSEE Team (FOSSEE IITB) Basic Python 13 / 45
14 Strings... Data types Strings Strings are immutable In []: w[0] = H TypeError Traceback (most recent call la <ipython console> in <module>() TypeError: str object does not support item assignment FOSSEE Team (FOSSEE IITB) Basic Python 14 / 45
15 Strings... Data types Strings Strings are immutable In []: w[0] = H TypeError Traceback (most recent call la <ipython console> in <module>() TypeError: str object does not support item assignment FOSSEE Team (FOSSEE IITB) Basic Python 14 / 45
16 Finding the type Data types Strings In []: a = 1.0 In []: type(a) Out[]: float In []: type(1) Out[]: int In []: type(1+1j) Out[]: complex In []: type( hello ) Out[]: str FOSSEE Team (FOSSEE IITB) Basic Python 15 / 45
17 Outline Operators 1 Data types Numbers Booleans Strings 2 Operators 3 Simple IO FOSSEE Team (FOSSEE IITB) Basic Python 16 / 45
18 Operators Arithmetic operators In []: 1786 % 12 Out[]: 10 In []: 45 % 2 Out[]: 1 In []: % 10 Out[]: 5 In []: 3124 * Out[]: In []: big = ** 3 In []: verybig = big * big * big * big FOSSEE Team (FOSSEE IITB) Basic Python 17 / 45
19 Operators Arithmetic operators In []: 17 / 2 Out[]: 8.5 # 8 on Python 2.x In []: 17 / 2.0 Out[]: 8.5 In []: 17.0 / 2 Out[]: 8.5 In []: 17.0 / 8.5 Out[]: 2.0 FOSSEE Team (FOSSEE IITB) Basic Python 18 / 45
20 Operators Arithmetic operators: floor division In []: 17 // 2 Out[]: 8 In []: 17 // 2.0 Out[]: 8.0 In []: 17.0 // 2.0 Out[]: 8.0 In []: 17.0 // 8.6 Out[]: 1.0 FOSSEE Team (FOSSEE IITB) Basic Python 19 / 45
21 Operators Arithmetic operators In []: c = 3+4j In []: abs(c) Out[]: 5.0 In []: c.imag Out[]: 4.0 In []: c.real Out[]: 3.0 In []: c.conjugate() (3-4j) FOSSEE Team (FOSSEE IITB) Basic Python 20 / 45
22 Operators Arithmetic operators In []: a = 7546 In []: a += 1 In []: a Out[]: 7547 In []: a -= 5 In []: a In []: a *= 2 In []: a /= 5 FOSSEE Team (FOSSEE IITB) Basic Python 21 / 45
23 Operators String operations In []: s = Hello In []: p = World In []: s + p Out[]: HelloWorld In []: s * 4 Out[]: HelloHelloHelloHello FOSSEE Team (FOSSEE IITB) Basic Python 22 / 45
24 Operators String operations... In []: s * s TypeError Traceback (most recent call la <ipython console> in <module>() TypeError: can t multiply sequence by non-int of type str FOSSEE Team (FOSSEE IITB) Basic Python 23 / 45
25 Operators String operations... In []: s * s TypeError Traceback (most recent call la <ipython console> in <module>() TypeError: can t multiply sequence by non-int of type str FOSSEE Team (FOSSEE IITB) Basic Python 23 / 45
26 Operators String methods In []: a = Hello World In []: a.startswith( Hell ) Out[]: True In []: a.endswith( ld ) Out[]: True In []: a.upper() Out[]: HELLO WORLD In []: a.lower() Out[]: hello world FOSSEE Team (FOSSEE IITB) Basic Python 24 / 45
27 Operators String methods In []: a = Hello World In []: b = a.strip() In []: b Out[]: Hello World In []: b.index( ll ) Out[]: 2 In []: b.replace( Hello, Goodbye ) Out[]: Goodbye World FOSSEE Team (FOSSEE IITB) Basic Python 25 / 45
28 Operators Strings: split & join In []: chars = a b c In []: chars.split() Out[]: [ a, b, c ] In []:.join([ a, b, c ]) Out[]: a b c In []: alpha =,.join([ a, b, c ]) In []: alpha Out[]: a, b, c In []: alpha.split(, ) Out[]: [ a, b, c ] FOSSEE Team (FOSSEE IITB) Basic Python 26 / 45
29 Operators String formatting In []: x, y = 1, In []: x is %s, y is %s %(x, y) Out[]: x is 1, y is %d, %f etc. available stdtypes.html FOSSEE Team (FOSSEE IITB) Basic Python 27 / 45
30 Operators Relational and logical operators In []: p, z, n = 1, 0, -1 In []: p == n Out[]: False In []: p >= n Out[]: True In []: n < z < p Out[]: True In []: p + n!= z Out[]: False FOSSEE Team (FOSSEE IITB) Basic Python 28 / 45
31 Operators The assert statement You will see it in tests and your exam! In []: assert p!= n In []: assert p == n AssertionError Traceback (most recent call l ----> 1 assert p == n AssertionError: No error if condition is True Raises error if False FOSSEE Team (FOSSEE IITB) Basic Python 29 / 45
32 Operators assert examples In []: assert p == n, "Oops condition failed" AssertionError Traceback (most recent call l ----> 1 assert p == n AssertionError: Oops condition failed Can supply an optional message FOSSEE Team (FOSSEE IITB) Basic Python 30 / 45
33 Operators String containership In []: fruits = apple, banana, pear In []: apple in fruits Out[]: True In []: potato in fruits Out[]: False Use tab complete to list other string methods Use? to find more information FOSSEE Team (FOSSEE IITB) Basic Python 31 / 45
34 Built-ins Operators In []: int(17 / 2.0) Out[]: 8 In []: float(17 // 2) Out[]: 8.0 In []: str(17 / 2.0) Out[]: 8.5 In []: round( 7.5 ) Out[]: 8.0 FOSSEE Team (FOSSEE IITB) Basic Python 32 / 45
35 Operators Odds and ends Case sensitive Dynamically typed need not specify a type In []: a = 1 In []: a = 1.1 In []: a = "Now I am a string!" Comments: In []: a = 1 # In-line comments In []: # A comment line. In []: a = "# Not a comment!" FOSSEE Team (FOSSEE IITB) Basic Python 33 / 45
36 Exercise 1 Operators Given a 2 digit integer x, find the digits of the number. For example, let us say x = 38 Find a way to get a = 3 and b = 8 using x? FOSSEE Team (FOSSEE IITB) Basic Python 34 / 45
37 Operators Possible Solution In []: a = x//10 In []: b = x%10 In []: a*10 + b == x FOSSEE Team (FOSSEE IITB) Basic Python 35 / 45
38 Operators Another Solution In []: sx = str(x) In []: a = int(sx[0]) In []: b = int(sx[1]) In []: a*10 + b == x FOSSEE Team (FOSSEE IITB) Basic Python 36 / 45
39 Exercise 2 Operators Given an arbitrary integer, count the number of digits it has. FOSSEE Team (FOSSEE IITB) Basic Python 37 / 45
40 Operators Possible solution In []: x = In []: len(str(x)) Sneaky solution! FOSSEE Team (FOSSEE IITB) Basic Python 38 / 45
41 Outline Simple IO 1 Data types Numbers Booleans Strings 2 Operators 3 Simple IO FOSSEE Team (FOSSEE IITB) Basic Python 39 / 45
42 Simple IO Simple IO: Console Input input() waits for user input. In []: a = input() 5 In []: a Out[]: 5 # Python 3.x! In []: a = input( Enter a value: ) Enter a value: 5 Prompt string is optional. input produces strings (Python 3.x) int() converts string to int. FOSSEE Team (FOSSEE IITB) Basic Python 40 / 45
43 Simple IO Simple IO: Python 2.x vs 3.x print is familiar to us Changed from Python 2.x to 3.x We use the Python 3 convention here If on Python 2.x do this: In []: from future import print_function Safe to use in Python 3.x also FOSSEE Team (FOSSEE IITB) Basic Python 41 / 45
44 Simple IO Simple IO: Console output Put the following code snippet in a file hello1.py from future import print_function print("hello", "World") print("goodbye", "World") Now run it like so: In []: %run hello1.py Hello World Goodbye World FOSSEE Team (FOSSEE IITB) Basic Python 42 / 45
45 Simple IO Simple IO: Console output... Put the following code snippet in a file hello2.py from future import print_function print("hello", end= ) print("world") Now run it like so: In []: %run hello2.py Hello World Mini Exercise Read docs for print Remember: use print? FOSSEE Team (FOSSEE IITB) Basic Python 43 / 45
46 Simple IO Simple IO: Console output... Put the following code snippet in a file hello2.py from future import print_function print("hello", end= ) print("world") Now run it like so: In []: %run hello2.py Hello World Mini Exercise Read docs for print Remember: use print? FOSSEE Team (FOSSEE IITB) Basic Python 43 / 45
47 Simple IO What did we learn? Data types: int, float, complex, boolean, string Use type builtin function to find the type Operators: +, -, *, /, %, **, +=, -=, *=, /=, >, <, <=, >=, ==,!=, a < b < c Simple IO: input and print FOSSEE Team (FOSSEE IITB) Basic Python 44 / 45
48 Homework Simple IO Explore the various string methods Read the documentation for the string methods Explore the different builtins seen so far also FOSSEE Team (FOSSEE IITB) Basic Python 45 / 45
Python: A great programming toolkit
Python: A great programming toolkit Asokan Pichai Prabhu Ramachandran Department of Aerospace Engineering IIT Bombay 25, July 2009 Acknowledgements This program is conducted by IIT, Bombay through CDEEP
More informationNot-So-Mini-Lecture 6. Modules & Scripts
Not-So-Mini-Lecture 6 Modules & Scripts Interactive Shell vs. Modules Launch in command line Type each line separately Python executes as you type Write in a code editor We use Atom Editor But anything
More informationFundamentals: Expressions and Assignment
Fundamentals: Expressions and Assignment A typical Python program is made up of one or more statements, which are executed, or run, by a Python console (also known as a shell) for their side effects e.g,
More informationFundamentals of Programming (Python) Getting Started with Programming
Fundamentals of Programming (Python) Getting Started with Programming Ali Taheri Sharif University of Technology Some slides have been adapted from Python Programming: An Introduction to Computer Science
More informationGetting Started with Python
Fundamentals of Programming (Python) Getting Started with Python Sina Sajadmanesh Sharif University of Technology Some slides have been adapted from Python Programming: An Introduction to Computer Science
More informationCSCI 121: Anatomy of a Python Script
CSCI 121: Anatomy of a Python Script Python Scripts We start by a Python script: A text file containing lines of Python code. Each line is a Python statement. The Python interpreter (the python3 command)
More informationENGR 101 Engineering Design Workshop
ENGR 101 Engineering Design Workshop Lecture 2: Variables, Statements/Expressions, if-else Edgardo Molina City College of New York Literals, Variables, Data Types, Statements and Expressions Python as
More informationComputer Components. Software{ User Programs. Operating System. Hardware
Computer Components Software{ User Programs Operating System Hardware What are Programs? Programs provide instructions for computers Similar to giving directions to a person who is trying to get from point
More informationIntroduction to computers and Python. Matthieu Choplin
Introduction to computers and Python Matthieu Choplin matthieu.choplin@city.ac.uk http://moodle.city.ac.uk/ 1 Objectives To get a brief overview of what Python is To understand computer basics and programs
More informationGetting Started Values, Expressions, and Statements CS GMU
Getting Started Values, Expressions, and Statements CS 112 @ GMU Topics where does code go? values and expressions variables and assignment 2 where does code go? we can use the interactive Python interpreter
More informationLab 1: Course Intro, Getting Started with Python IDLE. Ling 1330/2330 Computational Linguistics Na-Rae Han
Lab 1: Course Intro, Getting Started with Python IDLE Ling 1330/2330 Computational Linguistics Na-Rae Han Objectives Course Introduction http://www.pitt.edu/~naraehan/ling1330/index.html Student survey
More informationBasic Concepts. Computer Science. Programming history Algorithms Pseudo code. Computer - Science Andrew Case 2
Basic Concepts Computer Science Computer - Science - Programming history Algorithms Pseudo code 2013 Andrew Case 2 Basic Concepts Computer Science Computer a machine for performing calculations Science
More informationPython Programming: Lecture 2 Data Types
Python Programming: Lecture 2 Data Types Lili Dworkin University of Pennsylvania Last Week s Quiz 1..pyc files contain byte code 2. The type of math.sqrt(9)/3 is float 3. The type of isinstance(5.5, float)
More informationLessons on Python Numbers
Lessons on Python Numbers Walter Didimo [ 30 minutes ] Types of numbers There are only three kinds of number in Python: integer any integer number floating-point any real number complex any number having
More informationHere n is a variable name. The value of that variable is 176.
UNIT II DATA, EXPRESSIONS, STATEMENTS 9 Python interpreter and interactive mode; values and types: int, float, boolean, string, and list; variables, expressions, statements, tuple assignment, precedence
More informationScripting Languages. Python basics
Scripting Languages Python basics Interpreter Session: python Direct conversation with python (>>>) Python 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609] on linux Type "help", "copyright",
More informationIntroduction to Python
Introduction to Python Reading assignment: Perkovic text, Ch. 1 and 2.1-2.5 Python Python is an interactive language. Java or C++: compile, run Also, a main function or method Python: type expressions
More informationProgramming in Python 3
Programming in Python 3 Programming transforms your computer from a home appliance to a power tool Al Sweigart, The invent with Python Blog Programming Introduction Write programs that solve a problem
More informationVariables, expressions and statements
Variables, expressions and statements 2.1. Values and data types A value is one of the fundamental things like a letter or a number that a program manipulates. The values we have seen so far are 2 (the
More informationPython BASICS. Introduction to Python programming, basic concepts: formatting, naming conventions, variables, etc.
Python BASICS Introduction to Python programming, basic concepts: formatting, naming conventions, variables, etc. Identikit First appeared in 1991 Designed by Guido van Rossum General purpose High level
More informationCOMP519 Web Programming Lecture 17: Python (Part 1) Handouts
COMP519 Web Programming Lecture 17: Python (Part 1) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool Contents
More informationBasic Data Types and Operators CS 8: Introduction to Computer Science, Winter 2019 Lecture #2
Basic Data Types and Operators CS 8: Introduction to Computer Science, Winter 2019 Lecture #2 Ziad Matni, Ph.D. Dept. of Computer Science, UCSB Your Instructor Your instructor: Ziad Matni, Ph.D(zee-ahd
More informationBasic Scripting, Syntax, and Data Types in Python. Mteor 227 Fall 2017
Basic Scripting, Syntax, and Data Types in Python Mteor 227 Fall 2017 Basic Shell Scripting/Programming with Python Shell: a user interface for access to an operating system s services. The outer layer
More informationQUIZ: What value is stored in a after this
QUIZ: What value is stored in a after this statement is executed? Why? a = 23/7; QUIZ evaluates to 16. Lesson 4 Statements, Expressions, Operators Statement = complete instruction that directs the computer
More informationfrom scratch A primer for scientists working with Next-Generation- Sequencing data Chapter 1 Text output and manipulation
from scratch A primer for scientists working with Next-Generation- Sequencing data Chapter 1 Text output and manipulation Chapter 1: text output and manipulation In this unit you will learn how to write
More informationVariable and Data Type I
Islamic University Of Gaza Faculty of Engineering Computer Engineering Department Lab 2 Variable and Data Type I Eng. Ibraheem Lubbad September 24, 2016 Variable is reserved a location in memory to store
More informationAP Computer Science A
AP Computer Science A 1st Quarter Notes Table of Contents - section links Click on the date or topic below to jump to that section Date : 9/8/2017 Aim : Java Basics Objects and Classes Data types: Primitive
More informationIntroduction to Computer Programming CSCI-UA 2. Review Midterm Exam 1
Review Midterm Exam 1 Review Midterm Exam 1 Exam on Monday, October 7 Data Types and Variables = Data Types and Variables Basic Data Types Integers Floating Point Numbers Strings Data Types and Variables
More informationCSCE 110 Programming I Basics of Python: Variables, Expressions, Input/Output
CSCE 110 Programming I Basics of Python: Variables, Expressions, Input/Output Dr. Tiffani L. Williams Department of Computer Science and Engineering Texas A&M University Spring 2011 Python Python was developed
More informationBASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I
BASIC COMPUTATION x public static void main(string [] args) Fundamentals of Computer Science I Outline Using Eclipse Data Types Variables Primitive and Class Data Types Expressions Declaration Assignment
More informationMEIN 50010: Python Introduction
: Python Fabian Sievers Higgins Lab, Conway Institute University College Dublin Wednesday, 2017-10-04 Outline Goals Teach basic programming concepts Apply these concepts using Python Use Python Packages
More informationPython The way of a program. Srinidhi H Asst Professor Dept of CSE, MSRIT
Python The way of a program Srinidhi H Asst Professor Dept of CSE, MSRIT 1 Problem Solving Problem solving means the ability to formulate problems, think creatively about solutions, and express a solution
More informationIntermediate Programming, Spring 2017*
600.120 Intermediate Programming, Spring 2017* Misha Kazhdan *Much of the code in these examples is not commented because it would otherwise not fit on the slides. This is bad coding practice in general
More informationPrimitive Types. Four integer types: Two floating-point types: One character type: One boolean type: byte short int (most common) long
Primitive Types Four integer types: byte short int (most common) long Two floating-point types: float double (most common) One character type: char One boolean type: boolean 1 2 Primitive Types, cont.
More informationcosmos_python_ Python as calculator May 31, 2018
cosmos_python_2018 May 31, 2018 1 Python as calculator Note: To convert ipynb to pdf file, use command: ipython nbconvert cosmos_python_2015.ipynb --to latex --post pdf In [3]: 1 + 3 Out[3]: 4 In [4]:
More informationExpressions and Data Types CSC 121 Spring 2015 Howard Rosenthal
Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types
More informationEx: If you use a program to record sales, you will want to remember data:
Data Variables Programs need to remember values. Ex: If you use a program to record sales, you will want to remember data: A loaf of bread was sold to Sione Latu on 14/02/19 for T$1.00. Customer Name:
More informationComputational Physics
Computational Physics Intro to Python Prof. Paul Eugenio Department of Physics Florida State University Jan 16, 2018 http://comphy.fsu.edu/~eugenio/comphy/ Announcements Read Chapter 2 Python programming
More informationConstants. Variables, Expressions, and Statements. Variables. x = 12.2 y = 14 x = 100. Chapter
Variables, Expressions, and Statements Chapter 2 Unless otherwise noted, the content of this course material is licensed under a Creative Commons Attribution 3.0 License. http://creativecommons.org/licenses/by/3.0/.
More informationComputer Components. Software{ User Programs. Operating System. Hardware
Computer Components Software{ User Programs Operating System Hardware What are Programs? Programs provide instructions for computers Similar to giving directions to a person who is trying to get from point
More informationCOMP1730/COMP6730 Programming for Scientists. Strings
COMP1730/COMP6730 Programming for Scientists Strings Lecture outline * Sequence Data Types * Character encoding & strings * Indexing & slicing * Iteration over sequences Sequences * A sequence contains
More information18.1. CS 102 Unit 18. Python. Mark Redekopp
18.1 CS 102 Unit 18 Python Mark Redekopp 18.2 Credits Many of the examples below are taken from the online Python tutorial at: http://docs.python.org/tutorial/introduction.html 18.3 Python in Context Two
More informationMIT AITI Python Software Development
MIT AITI Python Software Development PYTHON L02: In this lab we practice all that we have learned on variables (lack of types), naming conventions, numeric types and coercion, strings, booleans, operator
More informationVariables and literals
Demo lecture slides Although I will not usually give slides for demo lectures, the first two demo lectures involve practice with things which you should really know from G51PRG Since I covered much of
More informationPython Input, output and variables
Today s lecture Python Input, output and variables Lecture 22 COMPSCI111/111G SS 2016! What is Python?! Displaying text on screen using print()! Variables! Numbers and basic arithmetic! Getting input from
More informationChapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.
Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of
More information\n is used in a string to indicate the newline character. An expression produces data. The simplest expression
Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of
More informationVariable and Data Type I
The Islamic University of Gaza Faculty of Engineering Dept. of Computer Engineering Intro. To Computers (LNGG 1003) Lab 2 Variable and Data Type I Eng. Ibraheem Lubbad February 18, 2017 Variable is reserved
More informationCS 106 Introduction to Computer Science I
CS 106 Introduction to Computer Science I 05 / 31 / 2017 Instructor: Michael Eckmann Today s Topics Questions / Comments? recap and some more details about variables, and if / else statements do lab work
More informationCIS192 Python Programming. Robert Rand. August 27, 2015
CIS192 Python Programming Introduction Robert Rand University of Pennsylvania August 27, 2015 Robert Rand (University of Pennsylvania) CIS 192 August 27, 2015 1 / 30 Outline 1 Logistics Grading Office
More informationGetting started with Java
Getting started with Java Magic Lines public class MagicLines { public static void main(string[] args) { } } Comments Comments are lines in your code that get ignored during execution. Good for leaving
More informationMobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02
Mobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02 Hello, in this lecture we will learn about some fundamentals concepts of java.
More informationPython Input, output and variables. Lecture 23 COMPSCI111/111G SS 2018
Python Input, output and variables Lecture 23 COMPSCI111/111G SS 2018 1 Today s lecture What is Python? Displaying text on screen using print() Variables Numbers and basic arithmetic Getting input from
More informationIntroduction to Python Code Quality
Introduction to Python Code Quality Clarity and readability are important (easter egg: type import this at the Python prompt), as well as extensibility, meaning code that can be easily enhanced and extended.
More informationPython Input, output and variables. Lecture 22 COMPSCI111/111G SS 2016
Python Input, output and variables Lecture 22 COMPSCI111/111G SS 2016 Today s lecture u What is Python? u Displaying text on screen using print() u Variables u Numbers and basic arithmetic u Getting input
More informationExam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming
Exam 1 Prep Dr. Demetrios Glinos University of Central Florida COP3330 Object Oriented Programming Progress Exam 1 is a Timed Webcourses Quiz You can find it from the "Assignments" link on Webcourses choose
More informationLecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University
Lecture 2 COMP1406/1006 (the Java course) Fall 2013 M. Jason Hinek Carleton University today s agenda a quick look back (last Thursday) assignment 0 is posted and is due this Friday at 2pm Java compiling
More informationPython Programming Exercises 1
Python Programming Exercises 1 Notes: throughout these exercises >>> preceeds code that should be typed directly into the Python interpreter. To get the most out of these exercises, don t just follow them
More informationCSI33 Data Structures
Outline Department of Mathematics and Computer Science Bronx Community College October 24, 2018 Outline Outline 1 Chapter 8: A C++ Introduction For Python Programmers Expressions and Operator Precedence
More informationUNIVERSITÀ DI PADOVA. < 2014 March >
UNIVERSITÀ DI PADOVA < 2014 March > Easy-to-learn: Python has relatively few keywords, simple structure, and a clearly defined syntax. Easy-to-read: Python code is much more clearly defined and visible
More informationPython for Non-programmers
Python for Non-programmers A Gentle Introduction 1 Yann Tambouret Scientific Computing and Visualization Information Services & Technology Boston University 111 Cummington St. yannpaul@bu.edu Winter 2013
More informationCSE 115. Introduction to Computer Science I
CSE 115 Introduction to Computer Science I Note about posted slides The slides we post will sometimes contain additional slides/content, beyond what was presented in any one lecture. We do this so the
More informationInteractive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D
1/60 Interactive use $ python Python 2.7.5 (default, Mar 9 2014, 22:15:05) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin Type "help", "copyright", "credits" or "license" for more information.
More informationCSCE 110: Programming I
CSCE 110: Programming I Sample Questions for Exam #1 February 17, 2013 Below are sample questions to help you prepare for Exam #1. Make sure you can solve all of these problems by hand. For most of the
More informationIntroduction to Python
Introduction to Python خانه ریاضیات اصفهان فرزانه کاظمی زمستان 93 1 Why Python? Python is free. Python easy to lean and use. Reduce time and length of coding. Huge standard library Simple (Python code
More informationJava Bytecode (binary file)
Java is Compiled Unlike Python, which is an interpreted langauge, Java code is compiled. In Java, a compiler reads in a Java source file (the code that we write), and it translates that code into bytecode.
More informationVariables, Expressions, and Statements
Variables, Expressions, and Statements Chapter 2 Python for Informatics: Exploring Information www.pythonlearn.com Constants Fixed values such as numbers, letters, and strings are called constants because
More informationIntro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming
Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals
More informationDEBUGGING TIPS. 1 Introduction COMPUTER SCIENCE 61A
DEBUGGING TIPS COMPUTER SCIENCE 61A 1 Introduction Every time a function is called, Python creates what is called a stack frame for that specific function to hold local variables and other information.
More informationAccelerating Information Technology Innovation
Accelerating Information Technology Innovation http://aiti.mit.edu/program/philippines-summer-2012/ Philippines Summer 2012 Lecture 1 Introduction to Python June 19, 2012 Agenda About the Course What is
More informationChapter 2: Data and Expressions
Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University January 15, 2015 Chapter 2: Data and Expressions CS 121 1 / 1 Chapter 2 Part 1: Data
More informationA simple interpreted language
Copyright Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See http://software-carpentry.org/license.html for more information. A simple interpreted language
More informationChapter 2: Data and Expressions
Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University April 21, 2015 Chapter 2: Data and Expressions CS 121 1 / 53 Chapter 2 Part 1: Data Types
More informationCompound Data Types 1
Compound Data Types 1 Chapters 8, 10 Prof. Mauro Gaspari: mauro.gaspari@unibo.it Compound Data Types Strings are compound data types: they are sequences of characters. Int and float are scalar data types:
More informationHello, World! An Easy Intro to Python & Programming. Jack Rosenthal
An Easy Intro to Python & Programming Don t just buy a new video game, make one. Don t just download the latest app, help design it. Don t just play on your phone, program it. No one is born a computer
More informationPython I. Some material adapted from Upenn cmpe391 slides and other sources
Python I Some material adapted from Upenn cmpe391 slides and other sources Overview Names & Assignment Data types Sequences types: Lists, Tuples, and Strings Mutability Understanding Reference Semantics
More informationCS 1803 Pair Homework 3 Calculator Pair Fun Due: Wednesday, September 15th, before 6 PM Out of 100 points
CS 1803 Pair Homework 3 Calculator Pair Fun Due: Wednesday, September 15th, before 6 PM Out of 100 points Files to submit: 1. HW3.py This is a PAIR PROGRAMMING Assignment: Work with your partner! For pair
More informationInteractive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D
1/58 Interactive use $ python Python 2.7.5 (default, Mar 9 2014, 22:15:05) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin Type "help", "copyright", "credits" or "license" for more information.
More informationAt full speed with Python
At full speed with Python João Ventura v0.1 Contents 1 Introduction 2 2 Installation 3 2.1 Installing on Windows............................ 3 2.2 Installing on macos............................. 5 2.3
More informationExpressions and Data Types CSC 121 Fall 2015 Howard Rosenthal
Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types and
More informationSequence types. str and bytes are sequence types Sequence types have several operations defined for them. Sequence Types. Python
Python Sequence Types Sequence types str and bytes are sequence types Sequence types have several operations defined for them Indexing Python Sequence Types Each element in a sequence can be extracted
More informationCourse Outline. Introduction to java
Course Outline 1. Introduction to OO programming 2. Language Basics Syntax and Semantics 3. Algorithms, stepwise refinements. 4. Quiz/Assignment ( 5. Repetitions (for loops) 6. Writing simple classes 7.
More informationIntroductory Scientific Computing with Python
Introductory Scientific Computing with Python More plotting, lists and FOSSEE Department of Aerospace Engineering IIT Bombay SciPy India, 2015 December, 2015 FOSSEE (FOSSEE IITB) Interactive Plotting 1
More informationLecture 1. Types, Expressions, & Variables
Lecture 1 Types, Expressions, & Variables About Your Instructor Director: GDIAC Game Design Initiative at Cornell Teach game design (and CS 1110 in fall) 8/29/13 Overview, Types & Expressions 2 Helping
More informationIntermediate/Advanced Python. Michael Weinstein (Day 1)
Intermediate/Advanced Python Michael Weinstein (Day 1) Who am I? Most of my experience is on the molecular and animal modeling side I also design computer programs for analyzing biological data, particularly
More informationComp 151. More on Arithmetic and number types
Comp 151 More on Arithmetic and number types Admin Any questions 2 Strings Remember Strings from last time Strings represent text. Discussion of data representation in a computer 1000001 = 65 (A) 110000
More informationStrings. CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington
Strings CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1 Strings Store Text In the same way that int and float are designed to store numerical values,
More informationWeek 2. expressions, variables, for loops
Week expressions, variables, for loops Special thanks to Scott Shawcroft, Ryan Tucker, Paul Beck, Hélène Martin, Kim Todd, John Kurkowski, and Marty Stepp for their work on these slides. Except where otherwise
More informationCOMP1730/COMP6730 Programming for Scientists. Data: Values, types and expressions.
COMP1730/COMP6730 Programming for Scientists Data: Values, types and expressions. Lecture outline * Data and data types. * Expressions: computing values. * Variables: remembering values. What is data?
More informationProgramming for Engineers in Python. Recitation 1
Programming for Engineers in Python Recitation 1 Plan Administration: Course site Homework submission guidelines Working environment Python: Variables Editor vs. shell Homework 0 Python Cont. Conditional
More informationPython Intro GIS Week 1. Jake K. Carr
GIS 5222 Week 1 Why Python It s simple and easy to learn It s free - open source! It s cross platform IT S expandable!! Why Python: Example Consider having to convert 1,000 shapefiles into feature classes
More informationData Science Python. Anaconda. Python 3.x. Includes ALL major Python data science packages. Sci-kit learn. Pandas.
Data Science Python Anaconda Python 3.x Includes ALL major Python data science packages Sci-kit learn Pandas PlotPy Jupyter Notebooks www.anaconda.com Python - simple commands Python is an interactive
More informationCMPT 120 Basics of Python. Summer 2012 Instructor: Hassan Khosravi
CMPT 120 Basics of Python Summer 2012 Instructor: Hassan Khosravi Python A simple programming language to implement your ideas Design philosophy emphasizes code readability Implementation of Python was
More informationLecture 4. Defining Functions
Lecture 4 Defining Functions Academic Integrity Quiz Reading quiz about the course AI policy Go to http://www.cs.cornell.edu/courses/cs11110/ Click Academic Integrity in side bar Read and take quiz in
More informationCollections. Lists, Tuples, Sets, Dictionaries
Collections Lists, Tuples, Sets, Dictionaries Homework notes Homework 1 grades on canvas People mostly lost points for not reading the document carefully Didn t play again Didn t use Y/N for playing again
More informationBuilt-in Types of Data
Built-in Types of Data Types A data type is set of values and a set of operations defined on those values Python supports several built-in data types: int (for integers), float (for floating-point numbers),
More informationFull file at
Gaddis: Starting Out with Java: Early Objects, 4/e Test Bank 1 Chapter 2 Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) Which of the
More informationCS 111X - Fall Test 1 - KEY KEY KEY KEY KEY KEY KEY
CS 111X - Fall 2016 - Test 1 1/9 Computing ID: CS 111X - Fall 2016 - Test 1 - KEY KEY KEY KEY KEY KEY KEY Name: Computing ID: On my honor as a student, I have neither given nor received unauthorized assistance
More informationProgramming to Python
Programming to Python Sept., 5 th Slides by M. Stepp, M. Goldstein, M. DiRamio, and S. Shah Compiling and interpreting Many languages require you to compile (translate) your program into a form that the
More informationLaboratory Exercise #0
Laboratory Exercise #0 This assignment focuses on the mechanics of installing and using Python. The deadline for Mimir submission is 11:59 PM on Monday, January 8. 1. Complete the steps given below to
More information