Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
() "" ("") Basic help
#1
Hello What are the exact rules using these signs
"" : () and_this
(" i no this means print eveything inside ") "but how about when its like this " (or this)
i just finished my first tutorial i keep messing up because i cant seem to find a clear cut answer for this
Reply
#2
Well, your question isn't very clear. Parentheses can mean a lot of things. They can be a function call: func_name(argument). They can define a tuple, which is a type of sequence: (8, 0, 1). They can also force a different order of resolution in an expression: (1 + 2) * 3. They can define parameters in a function definition: def foo(bar = 'eggs'):. The can specify a parent class in a class definition: class Dog(Animal):.

Colon generally goes at the end of a statement and indicates an indented block of code that is associated with that statement. It can be a class or def statement, a conditional statement (if/elif/else), a loop (for/while), a try/except block, and maybe some others I've forgotten. A colon is also used in a dictionary definition: colors = {'Lancelot': 'blue', 'Galahad': 'green'}.

Quotes start a string literal. Three of them in a row start a multi-line string literal. Parentheses inside quotes are part of the string literal. Quotes inside parentheses depend on what the parentheses are doing.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
This isn't an answer, more just a general comment. At first your answer did seem unclear, and then I flashed back on when I first started doing programming, and I thought at the time that there should be a list of the rules of the language C, the way that there's a list of the rules of the game of chess.

However, there really isn't such a list of rules for programmer usage. Interpreters (or compilers in the case of compiled languages) do have a list of rules, but I don't think it's terribly helpful for an actual programmer. You could go through the spec yourself,for example at https://docs.python.org/3/reference/lexi...delimiters it says this about double-quotes ("), "The following printing ASCII characters have special meaning as part of other tokens or are otherwise significant to the lexical analyzer:

' " # \"

Mostly you just have try out examples, and see what works and what doesn't, and infer the rules from that.

But @ichabod801 gave a more direct answer to your question.
Reply
#4
And maybe if you had specific examples where the symbols are confusing you or causing errors, we could address those situations specifically.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#5
Thank you all this seems like it one of those things where i have to just keep chugging along until i get it down. thanks!!!!
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020