Python (Guido van Rossum) programming hub

Ace your homework & exams now with Quizwiz!

which of the following statements are true for a variable? a. variables can be numbers and strings. b. containers c. variables are used to store data d. variables in Python need to be declared

a. variables can be numbers and strings. b. containers c. variables are used to store data

which of the following is the correct way to print hello world on the screen.? A. print(hello world) B. print"hello world" C. Hello World D. print ("hello world")

D. print ("hello world")

print()

a function in Python to display things on a screen a built-in function is a function which is predefined and can be used directly

to summarize python is:

a set of instructions. print() function can be used to write in the output screen. the text to be printed has to be enclosed in quotes (" ") print () is a built-in function. # is used to write comments in Python.

comments in Python

comments are pieces of code which are ignored by the python interpreter. comments are written to make source code easier to understand by other people. python support single line comment which means they can cover only one line. anything written following # is considered a single line comment in Python. # this is a python comment.

myVar2 = 25.54 a floating-point number

because myVAR has a value of 25.54 it is a floating-point number. whether an integer or a floating-point number python views both in one category as numbers. no need to specify the type manually because python does it automatically.

which of the following statements best describes a program? a language used to give instructions to a computer. set of instructions that tells the computer to perform a specific task a way of solving problems anything written on a computer.

set of instructions that tells the computer to perform a specific task

storing data in variables

the variable name, value and assignment operator (=) are the three things required to store values in the variables myVar = 60 here, myVar is the variable name and it is assigned a value of 60 using the assignment operator ('='). so myVAR is a variable with the value of 60. "variables don't need to be declared " as seen in other languages

terms

we can store numbers in variables numbers containing a decimal point are known as floating point numbers in programming a floating Point number refers to a number consisting of two parts separated by a decimal point a whole number is known as integer in programming

programming language

a language used to create programs

program

a program is a set of instructions that tells the computer to perform a specific task.

what is the correct way to declare a string in Python and assign it a value "Hello"? a. string newVar("Hello") b. newVar = "Hello" c. newVar = string(Hello) d. "Hello" = newVar

b. newVar = "Hello"

variables in Python can be referred using: ? variable names address of variables

correct answer equals variable names

myVar1 = "Hello"

here myVar1 is a string having the value "hello".

let's see how numbers are stored in Python

myVar = 2 # an integer myVar which has a value of 2 is an integer.

print ("Hello World")

output= HELLO WORLD = ACTUAL PYTHON PROGRAM

which of the following statements are used to display text on screen in Python? printf printout print cout

print

Text values

strings = a sequence of characters anything written between " " or ' ' is a string in Python.

if we want to display anything on the screen it needs to be written inside brackets and enclosed with double quotes " " . true or false

true

variables in programming

act as containers to store values. can be numbers to text or other functions variables are identified by variable names. the values stored in our variables can be used further in our programs. how.? we can retrieve them by referring to the variable names which are used to identify these variables.

which of the following are not a floating-point number? a. 12.2 b. 3 c. 34.5 d. 4

answer = 3 and 4 neither three or four are floating Point numbers they are integers.

examples of python string

"Hello3" or "456" or 'hello' or '45number'

which of the following is used to write comments in Python. ? // # *

#

Integer

An integer (pronounced IN-tuh-jer) is a whole number (not a fractional number) that can be positive, negative, or zero. Examples of integers are: -5, 1, 5, 8, 97, and 3,043. Examples of numbers that are not integers are: -1.43, 1 3/4, 3.14, .09, and 5,643.1.

how can we create a variable in yourVar and assign it a value of 45 in Python? a. intyourVar = 45 b. yourVar == 45 c. yourVar = 45 d. none of the above

c. yourVar = 45

to summarize

in programming, variables are containers which can be used to store values. values can be numbers or strings. strings are written inside of "" ( double quotes) or '' (single quotes) these variables are referenced using their variable names

proper syntax of declaring a value is _ Variable_name=variable_value variable_value= variable_name.

A set of values. The type of a value determines how it can be used in expressions. So far, the types you have seen are integers ( int ), floating-point numbers ( float ), and strings ( str ). ... A Python data type which stores floating-point numbers. A Python variable's name is a key in the global (or local) namespace, which is effectively a dictionary. The underlying value is some object in memory. Assignment gives a name to that object. Assignment of one variable to another variable means both variables are names for the same object. Jul 12, 2017 Syntax is the order or arrangement of words and phrases to form proper sentences. The most basic syntax follows a subject + verb + direct object formula. That is, "Jillian hit the ball." Syntax allows us to understand that we wouldn't write, "Hit Jillian the ball." variable_name = variable_value

print()

The BASIC command PRINT is used to print data onto the screen. In place of variables (strings, integers or floating point), any mathematical term or BASIC function can be used. It is important to put strings, graphic and control chars between quotes (" "). A "Hello, World!" program generally is a computer program that outputs or displays the message "Hello, World!". Such a program is very simple in most programming languages, and is often used to illustrate the basic syntax of a programming language. It is often the first program written by people learning to code. It can also be used as a sanity test to make sure that a computer language is correctly installed, and that the operator understands how to use it


Related study sets

NCLEX Psychosocial Alterations (Mod 4)

View Set

American Gov - Test 3 Presidency and Federal Admin

View Set

Exam 261: Contact Center Analytics (5%)

View Set

Episode 11: How to Train a Brain

View Set

Child with an integumentary disorder

View Set