MD1 Create a basic Python script Flashcards

1
Q

When we work in Python, we refer to what we write as a “script” or a “program.” There are subtle differences between the two.

A

Let’s compare a computer program to a theater performance. Almost every theater performance includes a written script. Actors study and memorize a script to say it out loud to an audience. However, that’s not the only component. There’s also the whole performance. Directors make decisions on what lighting to use, or costumes, or what the stage looks like. The performance as a whole involves a lot of design choices, like set design, lighting, and costumes. The process of creating this production is similar to the process of programming in Python. Programming involves a lot of design decisions. But the process of scripting in Python is more like writing the specific words that the actors will say. In Python, it’s good practice to start with a comment.

A comment is a note programmers make about the intention behind their code. Let’s add one now.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

A comment

A

A comment is a note programmers make about the intention behind their code. Let’s add one now.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Print ( )

A

Print outputs a specified object to the screen

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Syntax

A

Syntax refers to the rules that determine what is correctly structured in a computing language.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

code example

A

We start with the hash symbol to indicate that this is a comment. And then we’ll add details about our intention. Here we’re going to print “Hello Python” to the screen. Okay, now let’s write our first line of Python code. This code uses print. Print outputs a specified object to the screen. After print, we put what we want to output in parentheses. In this case, we want to output the string “Hello Python!” We must place string data in quotation marks. These quotation marks are just one example of syntax that you will encounter in Python. Syntax refers to the rules that determine what is correctly structured in a computing language. And now, we’ll run this code so the computer can output the string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly