Declare variable without assigning any value in Python?

0 votes

for index in sequence:


   if value == None and conditionMet:
       value = index
       break

Oct 29, 2018 in Python by findingbugs
• 3,260 points
1,347 views

1 answer to this question.

0 votes
var = None

Python is dynamic, so you don't need to declare things; they exist automatically in the first scope where they're assigned. So, all you need is a regular old assignment statement as above.

This is nice, because you'll never end up with an uninitialized variable. But be careful -- this doesn't mean that you won't end up with incorrectly initialized variables. If you init something to None, make sure that's what you really want, and assign something more meaningful if you can.

answered Oct 29, 2018 by Priyaj
• 57,700 points

Related Questions In Python

0 votes
0 answers

How can we pass a variable value in python GOTO statement?

Alias is a runtime argument the value ...READ MORE

Feb 5 in Python by neppoliean
• 120 points
166 views
+4 votes
7 answers
+2 votes
11 answers
0 votes
1 answer

Obtaining a value when given a key in python dicionaries

We cannot. Dictionaries aren't meant to be ...READ MORE

answered May 31, 2018 in Python by Nietzsche's daemon
• 4,260 points
113 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,584 views
0 votes
0 answers
0 votes
1 answer

How can I print variable and string on same line in Python?

Use , to separate strings and variables while printing: print ...READ MORE

answered Sep 17, 2018 in Python by Priyaj
• 57,700 points
1,462 views
+1 vote
1 answer

Python: Print variable and string in same line

For a better understanding you can refer ...READ MORE

answered Oct 30, 2018 in Python by Priyaj
• 57,700 points
619 views