Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to take first digit of number python

>>> number = 1520
>>> int(str(number)[:2])
15
Comment

how to take first digit of number python

import math

def first_n_digits(num, n):
    return num // 10 ** (int(math.log(num, 10)) - n + 1)
Comment

PREVIOUS NEXT
Code Example
Python :: python add one month to a date 
Python :: np.reshape() 
Python :: thread syntax in python 
Python :: how many columns can a pandas dataframe have 
Python :: check if list elememnt in dataframe column 
Python :: count occurrences of character in string python using dictionary 
Python :: python calculator file size to megabytes 
Python :: paradigm meaning in python 
Python :: python enum advanced 
Python :: read list from txt python 
Python :: post request socket python 
Python :: heatmap in python 
Python :: ipynb import 
Python :: Code of recursive binary search 
Python :: live server python 
Python :: python help 
Python :: diamond shape in python 
Python :: append two list of number to one python 
Python :: flask flash 
Python :: pd.datafram 
Python :: python switch case 3.10 Structural Pattern Matching 
Python :: get the name of all files in a computer in python 
Python :: how to print all items in a list python 
Python :: docker build python fastapi 
Python :: escape sequence in python 
Python :: python set with counts 
Python :: how to declare np datetime 
Python :: python webbrowser module 
Python :: python reduce 
Python :: hugingface ner 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =