+ 2
(Python) Statement/Function/Syntax construct/Object
What are the differences?
12 Réponses
+ 6
Zoe print() is a built in function and what goes in side is a statement but a sytax construct is the set of rules that defines how a Python program will be written and interpreted.
When you create a custom function you are passing an object to the function which is defined as a syntax costruct
def house(color, price):
print(f"my house is a two story {color} house and it cost ${price}") #function print and statement
color = input() # variable passed by built in function
price = input() # variable passed by built in function
house(color, price) #calling custom function and passing objects to function
* hope I explained this clear enough.
+ 2
I think "syntax construct" in this context just means "a piece of syntactically valid code".
In Python, "everything" is an object that's why sometimes even functions are called objects. (This is not necessarily the same in other programming language.)
To understand what an "object" in terms of programming means, one needs to understand a paradigm called "object oriented programming". The basic idea is that each thing belongs to a certain type ("class") of objects and this determines which properties and behaviors it may have. It is a more advanced concept that is only introduced later in the sololearn courses. It's okay if it isn't clear yet!
+ 2
Zoe ,
I have also noticed Sololearn write things like "the print statement", and wondered if it would mislead newbies.
It's just a loose way of saying, "a statement containing a print function call" or "a statement that calls the print function", etc.
I've actually had trouble nailing down a good writer's text definition of a statement.
A statement basically means a line of code.
However, you can stick multiple statements on the same line if you separate them with semicolons.
x = 10; y = 11; print(x + y) # 21
And you can spread one statement over multiple lines with Python's free formatting within any kind of () {} [] brackets,
my_list = [
"cellophane",
"cellulose",
"celluloid",
"cell",
"cellular",
"cellphone",
]
or by escaping the newline character.
long_word = "supercalifragilistic\
expialidocious"
+ 2
'''
Zoe ,
There are also compound statements, such as the if compound statement, which are higher-order syntax structures containing multiple regular statements.
A compound statement has one or more clauses, and each clause has a header and a suite.
Each header starts with a keyword and ends with a colon.
A suite is the block of indented statements below a header that are controlled by that clause.
A clause is named after the keyword of its header, and a compound statement is named after its first clause.
'''
x = input()
# if compound statement below
if len(x) == 0: # header of if clause
print("empty") # suite of if clause
elif x == "two": # header of elif clause
print("2") # suite of elif clause
elif x == "2": # header of elif clause
print("two") # suite of elif clause
else: # header of else clause
print("dunno") # suite of else clause
+ 2
Zoe
The problem might be people rehashing old tutorials.
Python's print used to be a statement. It is now changed to a function.
https://snarky.ca/why-print-became-a-function-in-python-3/
""
So when sololearn says “ The print() statement is the easiest way to send a value on the screen.” This actually wrong and it should say function instead of statement?
""
----yes, they're wrong, unless it's a Python 2.x tutorial. Then it's still wrong because print did not use () back then...
+ 1
These are different concepts and their meanings depend on the context.
Provide some context in which you encounter the terms.
A function is a block of reusable code. Syntax is the grammar of the programming language. An object is a thing that has a certain data structure.
Continue the course.
+ 1
So when sololearn says “ The print() statement is the easiest way to send a value on the screen.” This actually wrong and it should say function instead of statement?
+ 1
Thank you Lisa, thank you BroFar.
+ 1
Thank you Rain.
+ 1
Thank you, Bob_Li
0
In sololearn sometimes it says print() is a function, and sometimes is says print() is a statement.
Somewhere in the internet I have read a statement is a syntax construct and a function is an object.
Now I am even more confused because I don’t know what a syntax construct and an object in python are. What do these words mean?