Ch 2 - Variables, Expressions, and Statements Flashcards

1
Q

Think Julia

What is: Assignment Statements

A

Assignment Statements

An assignment statement creates a new variable and gives it a value:

julia > message = “And now for something completely different” “And now for something completely different”

julia > n = 17
17

julia > π_val = 3.141592653589793
3.141592653589793

Ben Lauwens and Allen B. Downey. thinkjulia (Kindle Locations 392-402). Kindle Edition.

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

Think Julia

Rules for making a variable name.

A

Variable Names

Programmers generally choose names for their variables that are meaningful— they document what the variable is used for.

Variable names can be as long as you like. They can contain almost all Unicode characters (see “Characters”), but they can’t begin with a number.

It is legal to use uppercase letters, but it is conventional to use only lowercase for variable names.

Unicode characters can be entered via tab completion of LaTeX-like abbreviations in the Julia REPL.

The underscore character, _, can appear in a name. It is often used in names with multiple words, such as your_name or airspeed_of_unladen_swallow. If you give a variable an illegal name, you get a syntax error:

Ben Lauwens and Allen B. Downey. thinkjulia (Kindle Locations 413-423). Kindle Edition.

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

Think Julia

What is a: expression

A

An expression is a combination of values, variables, and operators. A value all by itself is considered an expression, and so is a variable, so the following are all legal expressions:

julia > 42
42

julia > n # n=17
17

julia > n + 25
42

Ben Lauwens and Allen B. Downey. thinkjulia (Kindle Locations 444-449). Kindle Edition.

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

Think Julia

What is a: statement

A

A statement is a unit of code that has an effect, like creating a variable or displaying a value:

julia > n = 17
17

julia > println( n)
17

Ben Lauwens and Allen B. Downey. thinkjulia (Kindle Locations 453-458). Kindle Edition.

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

Think Julia

What is a: interactive mode

A

So far we have run Julia in interactive mode, which means that you interact directly with the REPL. Interactive mode is a good way to get started, but if you are working with more than a few lines of code, it can be clumsy.

Ben Lauwens and Allen B. Downey. thinkjulia (Kindle Locations 465-467). Kindle Edition.

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

Think Julia

What is a: script mode

A

The alternative is to save code in a file called a script and then run Julia in script mode to execute the script. By convention, Julia scripts have names that end with .jl.

Ben Lauwens and Allen B. Downey. thinkjulia (Kindle Locations 467-470). Kindle Edition.

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

Think Julia

What is a (with regards to strings): *

A

The * operator performs string concatenation, which means it joins the strings by linking them end-to-end.

Ben Lauwens and Allen B. Downey. thinkjulia (Kindle Locations 538-543). Kindle Edition.

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

Think Julia

What is a (with regards to strings): ^

A

The ^ operator also works on strings; it performs repetition. For example, “Spam” ^ 3 is “SpamSpamSpam”. If one of the values is a string, the other has to be an integer.

Ben Lauwens and Allen B. Downey. thinkjulia (Kindle Locations 548-552). Kindle Edition.

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

Think Julia

What is a: #

A

For this reason, it is a good idea to add notes to your programs to explain in natural language what the program is doing. These notes are called comments, and they start with the # symbol:

# compute the percentage of the hour that has elapsed percentage = (minute * 100) / 60

Note: Good variable names can reduce the need for comments, but long names can make complex expressions hard to read, so there is a trade-off.

Ben Lauwens and Allen B. Downey. thinkjulia (Kindle Locations 578-580). Kindle Edition.

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

Think Julia

What is a: expression

A

expression

A combination of variables, operators, and values that represents a single result.

Ben Lauwens and Allen B. Downey. thinkjulia (Kindle Locations 611-613). Kindle Edition.

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

Think Julia

What is a: evaluate

A

evaluate

To simplify an expression by performing the operations in order to yield a single value.

Ben Lauwens and Allen B. Downey. thinkjulia (Kindle Locations 613-616). Kindle Edition.

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

Think Julia

What is a: statement

A

statement

A section of code that represents a command or action. So far, the statements we have seen are assignments and print statements.

Ben Lauwens and Allen B. Downey. thinkjulia (Kindle Locations 616-618). Kindle Edition.

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

Think Julia

What is: semantics

A

semantics

The meaning of a program.

Ben Lauwens and Allen B. Downey. thinkjulia (Kindle Locations 636-637). Kindle Edition.

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

Think Julia

What is a: semantic error

A

semantic error

An error in a program that makes it do something other than what the programmer intended.

Ben Lauwens and Allen B. Downey. thinkjulia (Kindle Locations 637-639). Kindle Edition.

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