Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with "For loop"
#5
if I'm not mistaken global does not define a variable. On a 2nd note you probably do not need to declare it a global variable unless there is a reason.
Examples:
#! /usr/bin/env python3

myvar = 'some text'
print(f'Outside -> {myvar}')

def myfunc():
    print(f'Inside function - > {myvar}')
myfunc()

class MyClass:
    def __init__(self):
        print(f'Inside class - > {myvar}')
MyClass()
Output:
Outside -> some text Inside function - > some text Inside class - > some text
define it to be a blank variable outside the if
de = ''
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Messages In This Thread
Help with "For loop" - by Vaelyn - Jun-23-2020, 06:45 PM
RE: Help with "For loop" - by menator01 - Jun-23-2020, 07:05 PM
RE: Help with "For loop" - by Vaelyn - Jun-23-2020, 07:23 PM
RE: Help with "For loop" - by Yoriz - Jun-23-2020, 07:09 PM
RE: Help with "For loop" - by menator01 - Jun-23-2020, 07:23 PM
RE: Help with "For loop" - by jefsummers - Jun-23-2020, 08:25 PM
RE: Help with "For loop" - by Vaelyn - Jun-23-2020, 08:53 PM

Forum Jump:

User Panel Messages

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