Download presentation
Presentation is loading. Please wait.
Published byShanon Geraldine Scott Modified over 9 years ago
1
Introduction to Python Dr. Bernard Chen Ph.D. University of Central Arkansas July 9 th 2012 CS4HS@UCA
2
Why do people use Python? Software Quality: Python is designed to be readable, and hence maintainable. Developer productivity: Python code is typically 1/3 to 1/5 the size of equivalent C++ or JAVA code
3
What can I do with Python? System Programming GUIs Internet Scripting Database Programming Games, Images, AI, XML and more
4
What are Python’s Technical Strength It’s OO It’s free It’s Portable It’s Powerful It’s Easy to use It’s Easy to learn
5
What is the Downside of Python? Perhaps the only downside to Python is that the execution speed may not always as fast as compiled languages such as C and C++ Python is not compiled all the way down to binary machine code, it compiled to byte code instead.
6
Who Uses Python Today? Google and Yahoo currently use Python in Internet service IBM use Python for hardware testing Industrial Light and Magic use Python in the production of movie animation For more details, visit www.python.orgwww.python.org
7
Install Python Go to http://www.python.org/download/releases/3.2/ and download Python3.2, then select Windows x86 MSI Installer (3.2) or Windows X86-64 MSI Installer (3.2)http://www.python.org/download/releases/3.2/Windows x86 MSI Installer (3.2)Windows X86-64 MSI Installer (3.2)
8
Install Python Or you can search for Python, choose “Download” and then select Python 3.2 Windows x86 MSI Installer or Python 3.2 Windows X86-64 MSI InstallerPython 3.2 Windows x86 MSI InstallerPython 3.2 Windows X86-64 MSI Installer
9
Hello World Program Implement by three different languages In C In JAVA In Python
10
“Hello World” in C main() { printf("hello, world\n"); }
11
“Hello World” in JAVA class myfirstjavaprog { public static void main(String args[]) { System.out.println("Hello World!"); }
12
“Hello World” in Python print (“Hello World!!”)
13
Be familiar with Python >>> print ("Hello, World! ") Hello, World! >>> 10 + 25 35 >>> 124 – 125 >>> 1/3 0.333333333333333
14
Python command print – Displays data, values, and expressions The single and double quotation mark string objects, which are collections of texts surrounded by quotes. Some Python commands
15
Be familiar with Python >>> print ("Hello, World! ") Hello, World! >>> "hello" 'hello' >>> "world" 'world' >>> "hello"+"world" 'helloworld'
16
Be familiar with Python >>> "hello" * 3 'hellohellohello' >>> "hello" * 300
17
>>> width = 20 >>> height = 45 >>> area = width * height >>> area 900 Declare a variable and assign its value Example: Area of a rectangle
18
>>> a=3 >>> b=4 >>> a+1 >>> b*3 >>> b/3 >>> b/3.0 >>> b**2 >>> 2+4.0 >>> 2.0**b What are the outputs? Why?
19
How do you run programs? Three different methods: 1. Interactive Coding 2. Files (such as NotePad, WordPad) 3. Integrated Development Environment (IDE)
20
Create and run a program in the Python IDLE From File -> New Window Type your program print ("Hello, World! ") Save your program (Give a name you like, such as test.py) Run the program (by selecting the Run Module or pressing the F5 key)
21
Your first Python program- hello.py # This program says hello and asks for my name. hello = 'Hello world! ' print(hello) print('What is your name?') myName = input() print('It is good to meet you, ' + myName)
22
hello.py executed sequentially # This program says hello and asks for my name. Any text following a # sign is a comment. Comments are not for the computer, but for you, the programmer. 1. hello = 'Hello world! ' # assign the string to a name 2. print(hello) # call the print( ) function 3. print('What is your name?') # call the print( ) function 4. myName = input() # call the input( ) function 5. print('It is good to meet you, ' + myName)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.