Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,885 questions

51,811 answers

573 users

How to create a 2D point data structure with two floating-point numbers in Python

3 Answers

0 votes
from collections import namedtuple

Point = namedtuple("Point", "x y")

p = Point(x=9.23, y=7.18)

print(p[0], p[1])
print(p.x, p.y)



'''
run:

9.23 7.18
9.23 7.18

'''

 



answered Dec 27, 2022 by avibootz
0 votes
class Point:
  def __init__(self, _x, _y):
    self.x= _x
    self.y = _y
   
  def PrintPoint(self):
    print(self.x, self.y)
    
p = Point(5.63, 7.42)
p.PrintPoint()



'''
run:

5.63 7.42

'''

 



answered Dec 27, 2022 by avibootz
0 votes
from dataclasses import dataclass

@dataclass
class Point:
    # Constructor
    x: float
    y: float



p = Point(x=3.42, y=4.91)
print(p.x, p.y)



'''
run:

3.42 4.91

'''

 



answered Dec 27, 2022 by avibootz
...