Python variables | Sololearn: Learn to code for FREE!

+5

Python variables

Is it possible to assign an integer as a string variable? For example: 1 = “Hello World”

5/14/2020 7:35:00 PM

Zach Janzen

47 Answers

New Answer

+16

No, a variable name is not allowed to start with a number. There are more rules: a variable name must start with a letter or an underscore, can only contain [ A-z 0-9 _ ] and is case sensitive

+9

Zach Janzen We can do like this 👇👇👇 _1="Kiibo"

+4

no you need to start with a letter or underscore

+3

Granger A variable can also start with an underscore (_) instead of text. As an example: _1 = 1 is perfectly valid

+3

No bro, in Python only Name of variable with letters, number but not at start, and you can use _

+2

Thank you.

+2

vars = ["1","2"',"3"] vars[1]=2

+2

intetesting! 𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥

+2

𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 interesting!

+1

Kiibo Ghayal, thats an interesting way.

+1

No, it's a rule that we can't use an integer in the first letter of a variable. if you try to assign an variable like '1 = "Hello world"', it will throw an error.

+1

No you can't assing a variable as an integer

+1

No,variable name cannot start with integer.

+1

DeX97 Yes, i forgot it 😅

+1

It is not possible, you can't start your variable with with numbers..

+1

Tar Tar plz remove your comment from this question

+1

No you can not use number for naming variables. Rules for Python variables: A variable name must start with a letter or the underscore character. A variable name cannot start with a number. A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _)

+1

No, because variable doesn't allow to start with any number. Like, 1_variable_name ×

+1

no, variables can never start by a number

+1

One of the basic rules of programming in any language is thet You can't start a variable with a number. It is true for Python also. You just can't start a variable with a number. If you really want to do it, you can use/do: _1="This works!" #This works! Hope it helped!