<p>在Python中,在任何数字前面添加<code>0</code>需要额外的</p>
<ul>
<li><p><code>x</code>(用于十六进制)后跟十六进制数字范围内的任何数字<code>0-9</code>或{<cd4>}或{<cd5>}。</p></li>
<li><p><code>o</code>(对于八进制)后跟八进制数字范围内的数字<code>0-7</code>。</p></li>
</ul>
<p>请看以下内容:</p>
<pre><code>>>> 0o7
7
>>> 0o71
57
>>> 0o713
459
>>>
>>> 0xa
10
>>> 0xA
10
>>> 0x67
103
>>>
</code></pre>
<blockquote>
<p>» If you exceed the range or if you don't use <code>x</code> | <code>o</code> after <code>0</code>.</p>
</blockquote>
^{pr2}$
<blockquote>
<p><strong>Suggestion:</strong> If you are still willing to use <code>0</code> & want to perform operations on phones (for testing) then you can use the below approach to update the numbers. </p>
<p>Here we will store phone number as string & whenever we will update that, we will remove <code>0</code> from front, convert the remaining part into an integer, add (any operation) ant convert back to its original (<code>0</code> in front) form & I think it is good.</p>
</blockquote>
<pre><code>>>> student_phone = "016165544"
>>>
>>> # Add 3 to this
...
>>> student_phone = "0" + str(int(student_phone.lstrip("0")) + 3)
>>>
>>> student_phone
'016165547'
>>>
</code></pre>
<p>最后,你可以这样打电话(除了第二个问题外,你已经在处理你的问题了)。在</p>
<pre><code>>>> class Student:
... def __init__(self, student_name, student_id, student_phone):
... self.student_name = student_name
... self.student_id = student_id
... self.student_phone = student_phone
...
>>> obj = Student("ELizaa",1253251,16165544)
>>> print("student name",obj.student_name,"\nstudent id",obj.student_id,"\nStudent phone",obj.student_phone)
student name ELizaa
student id 1253251
Student phone 16165544
>>>
>>> obj = Student("ELizaa",1253251,"016165544")
>>> print("student name",obj.student_name,"\nstudent id",obj.student_id,"\nStudent phone",obj.student_phone)
student name ELizaa
student id 1253251
Student phone 016165544
>>>
</code></pre>