Python Forum
Learning python specific syntax after using other scripting languages for years
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Learning python specific syntax after using other scripting languages for years
#7
If you really want things to be a specific way. You can make your own types.
# if you really want to string + int
# just make an override
class MyString(str):
	def __add__(self, value):
		if isinstance(value, (int, float)):
			return MyString(str.__add__(self, str(value)))
		else:
			return MyString(str.__add__(self, value))
			
a = MyString('Hello') + 5
a = a + 7
print(a)
99 percent of computer problems exists between chair and keyboard.
Reply


Messages In This Thread
RE: Learning python specific syntax after using other scripting languages for years - by Windspar - Dec-11-2017, 04:30 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Converting days to years in loop while computing values across grid cells Lightning1800 2 2,682 May-15-2018, 08:44 PM
Last Post: Lightning1800

Forum Jump:

User Panel Messages

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