Presentation is loading. Please wait.

Presentation is loading. Please wait.

Python Fundamentals: Hello World! Eric Shook Department of Geography Kent State University.

Similar presentations


Presentation on theme: "Python Fundamentals: Hello World! Eric Shook Department of Geography Kent State University."— Presentation transcript:

1 Python Fundamentals: Hello World! Eric Shook Department of Geography Kent State University

2 The Python Programming Language Python is an Open Source programming language It is easy to use and easy to learn how to program Python website: https://www.python.org/https://www.python.org/ Additional links:  Documentation: https://docs.python.org/3/https://docs.python.org/3/  Tutorial: https://docs.python.org/3/tutorial/index.htmlhttps://docs.python.org/3/tutorial/index.html  Reference Manual: https://docs.python.org/3/reference/index.htmlhttps://docs.python.org/3/reference/index.html Many online resources:  Google will help

3 A Python Statement mystring = "Hello World!"

4 Statement Breakdown mystring = "Hello World!" Variable Variables can hold values (think back to math class). They can be referred by a name such as x, name or this_is_a_variable

5 Statement Breakdown mystring = "Hello World!" Assignment The equals sign assigns the value: "Hello World!" to the variable: mystring

6 Statement Breakdown mystring = "Hello World!" Value Variable values can be: strings such as "hello" or numbers such as 123 or 3.14

7 Statement Breakdown mystring = "Hello World!" Statement A statement is a single command that tells the computer (Python interpreter) to do something.

8 Try it mystring = "Hello World!" helloworld.py $ nano helloworld.py $ python helloworld.py Command-line Terminal

9 Try it mystring = "Hello World!" helloworld.py $ nano helloworld.py $ python helloworld.py Command-line Terminal Nothing?

10 Print Function Statement Breakdown print(mystring) Function call A function is a defined piece of Python code that can be called upon such as a 'print' function that prints information to the screen: function_name( arguments ) Arguments Arguments also known as parameters are passed into functions. This parameter is a variable, but strings and numbers can also be arguments. (myvar, "string 1", 2345, 3.14)

11 Try it mystring = "Hello World!" print(mystring) helloworld.py $ nano helloworld.py $ python helloworld.py Hello World! Command-line Terminal Success!

12 Case Sensitivity Python is case-sensitive meaning that uppercase and lowercase letters may change the meaning of commands print Print PRINT pRINT PrInT http://en.wikipedia.org/wiki/Case_sensitivity Only 'print' can be used to print information to the screen

13 Bugs $ python helloworld.py File "helloworld.py", line 4 ^ SyntaxError: invalid syntax These are bugs and errors that you will see Not these bugs

14 Common Bugs Attention to detail is vital when programming, because the smallest error and cause hard-to-find bugs. Each of the lines below contain one error. Can you spot them all? mystring="Hello World!") print(Hello World") Print(mystring) mystring="He said "hi" how are you"

15 Common Bugs Fixed Attention to detail is vital when programming, because the smallest error and cause hard-to-find bugs. Each of the lines below contain one error. Can you spot them all? mystring="Hello World!") print("Hello World") print(mystring) mystring="He said 'hi' how are you"

16 Basic Data Types Integer: 2, 10, -5, 1323455 Floating point:3.14, 2.1111, -1.0 String:"Hello World!", "a", "I am tweeting #twitter" Boolean:True, False NoneThis is a special type that uses the word None to literally mean there is nothing here. None is different than "", 0, and 0.0, which indicate a value for the other types.

17 Expressions Variables and numbers can be combined in mathematical expressions that will be evaluated or calculated. Mathematical expressions combined with logical statements enable Python to be used for spatial data processing ExpressionValue x = 2 + 2the variable x is equal to the value 4 y = x * 3if x is equal to 4 then the value of y is 12 x = x + 2if x is equal to 4 then the new value of x is 6 x = 4 – 2the variable x is now equal to the value 2 x = 4 / 2the variable x is equal to the value 2

18 Comments i=0 # This is a comment # i=1 print "i=",i # Write the value of i i=0 The Result Comments Comments allow programmers to leave plain text explanations of code. Comments are started with a hash tag (#) and everything after the '#' is ignored by Python.

19 Try It 1.Create a Python program with 5 variables. Each variable should be a different basic type 2.Print the value of each variable 3.Try printing a string and a variable like this: x=5 print("x=",x) 4.Create 3 mathematical expressions and print out the result. Check to make sure the result is correct. 5.Create 2 variables that have values that are strings. Add the variables together and print out the result. Is it what you expect? If the result is unexpected look in the manual to understand the result. 6.Add a comment to your program. Run it again to see if anything changed.


Download ppt "Python Fundamentals: Hello World! Eric Shook Department of Geography Kent State University."

Similar presentations


Ads by Google