Python Forum
When do you put variables inside vs outside a function?
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
When do you put variables inside vs outside a function?
#6
There was no answer at all when I started to write mine. But my English practice is not enough so until I clear it from mistakes you posted yours.
I had a pause to make a coffee, eating few biscuits so... This happens Angel

One more.
You can see all methods of an object in the interpreter using the dir() function.
>>> dir(first_list)
['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
The names of these methods will tell you what they are doing. There are some special methods we call dunder methods ( those with names like __itter__ ) but this is another topic. To see more info about the methods you can use the help function.
>>> help(first_list.reverse)
Output:
Help on built-in function reverse: reverse(...) method of builtins.list instance L.reverse() -- reverse *IN PLACE*
Press 'q' to exit the help.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Messages In This Thread
RE: When do you put variables inside vs outside a function? - by wavic - Jun-02-2018, 06:44 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  with open context inside of a recursive function billykid999 1 603 May-23-2023, 02:37 AM
Last Post: deanhystad
  How do I call sys.argv list inside a function, from the CLI? billykid999 3 828 May-02-2023, 08:40 AM
Last Post: Gribouillis
  How to print variables in function? samuelbachorik 3 954 Dec-31-2022, 11:12 PM
Last Post: stevendaprano
  User-defined function to reset variables? Mark17 3 1,701 May-25-2022, 07:22 PM
Last Post: Gribouillis
  How to make global list inside function CHANKC 6 3,163 Nov-26-2020, 08:05 AM
Last Post: CHANKC
  Parameters aren't seen inside function Sancho_Pansa 8 2,982 Oct-27-2020, 07:52 AM
Last Post: Sancho_Pansa
  Do I have to pass 85 variables to function? Milfredo 10 4,370 Sep-26-2020, 10:13 PM
Last Post: Milfredo
  Creating a variables inside FOR loop zazas321 5 4,157 Sep-16-2020, 04:42 PM
Last Post: Naheed
  print function help percentage and slash (multiple variables) leodavinci1990 3 2,528 Aug-10-2020, 02:51 AM
Last Post: bowlofred
  Issues with storing variables outside of a function cerulean747 7 3,770 Apr-30-2020, 08:46 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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