#šŸ”’ Hello! I am new to this language and I have two small questions.

38 messages Ā· Page 1 of 1 (latest)

nova basin
#

When do we use quotation marks in Python code? Typically, we use them with strings, but there are times when we do not. For example, in the following line of code for a DataFrame:

a = pd.DataFrame(columnname, index=['a', 'b', 'c'])

we used quotation marks for the index values 'a', 'b', and 'c', but not for columnname. Why is that?

Another is the ValueError we encounter when we provide fewer index labels than the number of rows. But what happens if we provide more index labels than there are rows? And what about columns—what occurs if we specify more or fewer column names than the data structure allows?

bronze fjordBOT
#

@nova basin

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

earnest night
#

that is a list of a strings

lavish horizon
nova basin
#

Okay, so we don’t need quotes for variables, right? And what about the second one?

thorn vale
#

right

earnest night
nova basin
earnest night
#

experimenting is a great way to see

vocal moon
# nova basin Okay, so we don’t need quotes for variables, right? And what about the second on...

so both are strings as said but there’s an important time when you should use speech marks over quotations
lets say you want to print a string that also showcases a quote, if you only use quotation marks, you would end the string abruptly as it would signify the end. therefore, in a case like that, you would need to open your string with speech marks.

eg: my_string = ā€œThis is how I would put a quote inside a string: ā€˜Hi there Discordā€™ā€

#

i’ve always use speech marks because of this and because other languages don’t allow for both speech and quotation marks
you can use either as long as you are aware of when to not use quotation marks for a string

#

(if that’s what you were asking)

#

also with variable names, you don’t need quotes
a variable can or cannot be a string
it can be any data type
but if you assign a string to it, think of it as a house for that string
it, itself, is not the value.. it is just a representation of to store it

#

so you wouldn’t need to put it in quotes

earnest night
#

ā€œā€

#

these are not valid for a string

vocal moon
#

i can never find the right stuff on iphone

#

took me about 10 mins to embed that code alone

earnest night
#

also you can simply escape the quotes if you need to mix and match

#

!e

print("I said \"Hello Discord!\"")
bronze fjordBOT
earnest night
#

the \ in front of the " tells python "I want a literal quotation mark and this isn't the end of the string"

vocal moon
#

that’s acc really useful, thanks

#

i did not know that

#

ill use that for my openai api to show how prompts might be made

earnest night
#

it wouldn't matter for raw input

vocal moon
#

still useful for a more clean look compared to quotes and speech marks all getting tangled at the end of a string

#

thanks

earnest night
#

it gets real crazy when you start using string representations

#

!e

text = ''

for _ in range(6):
    text = repr(text)

print(text)
bronze fjordBOT
earnest night
#

one of my favourite silly python things

vocal moon
#

this is amazing

bronze fjordBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.