數字字串和文字型資料有什麼區別

2021-03-03 23:01:02 字數 5734 閱讀 6582

1樓:瑪麗亞阿五法

沒什bai

麼大的區別,就是文字du型欄位既大且慢zhi,濫用文字型字dao

段會使伺服器速度變慢。儘量少版用。權

字元型能夠儲存**嗎?如果可以,長度應該設為多大?如果不能的話,應該使用什麼型別去設定?

字元型不能存**,但能存**的路徑,blob型可以存**,要想存**要先將**轉化為二進位制資料儲存到blob欄位,但沒人這麼做,缺點一大堆懶的說了,所以一般都是儲存**的路徑

如/iamge/aa.jpg

2樓:平成紅冬

他們復的資料型別不同,使用起來制自然也不

bai同了,數值du型資料可以進行加減乘除zhi操作dao,字串則不行,而字串可以進行字串連線操作,比如將「123」和「456」連線起來,就是「123456」了,字串可以轉換成數值型,用到了一個函式,現在我想不起來了。

數字字串和數值型資料有什麼區別?

3樓:藍冰淺雪

他們的資料型別不同,使用起來自然也不同了,數值型資料可以進行加減乘除操作,字串則不行,而字串可以進行字串連線操作,比如將「123」和「456」連線起來,就是「123456」了,字串可以轉換成數值型,用到了一個函式,現在我想不起來了。

4樓:匿名使用者

字元型數字是由"0-9"及"."字元組成的字串數值型數字是10進位制或2進製表示的數字

前者轉換為數值數字可用val 函式來返回包含於字串內的數字,字串中是一個適當型別的數值。

用數值型數字表示數字的變數佔用較小的記憶體,例:

30000用字元型表示佔40位(5位元組)記憶體用integer 資料型別表示僅為 16位(2個位元組)的數值形式

python 字元與數字如何轉換

5樓:zer0小雪

python中字元與數字相互轉換用chr()即可。

python中的字元數字之間的轉換函式

int(x [,base ]) 將x轉換為一個整數

long(x [,base ]) 將x轉換為一個長整數

float(x ) 將x轉換到一個浮點數

***plex(real [,imag ]) 建立一個複數

str(x ) 將物件 x 轉換為字串

repr(x ) 將物件 x 轉換為表示式字串

eval(str ) 用來計算在字串中的有效python表示式,並返回一個物件

tuple(s ) 將序列 s 轉換為一個元組

list(s ) 將序列 s 轉換為一個列表

chr(x ) 將一個整數轉換為一個字元

unichr(x ) 將一個整數轉換為unicode字元

ord(x ) 將一個字元轉換為它的整數值

hex(x ) 將一個整數轉換為一個十六進位制字串

oct(x ) 將一個整數轉換為一個八進位制字串

chr(65)='a'

ord('a')=65

int('2')=2;

str(2)='2'

6樓:日time寸

整數字串轉換為對應的整數

int('12')

小數字串轉換為對應小數

float('12.34')

數字轉換為字串

str(123.45)

ascii碼轉換為相應字元

chr(97)

字元轉換為響應ascii碼

ord('a')

7樓:尼克的右手

一、python中字串轉換成數字(1)import string

t='555'

ts=string.atoi(tt)

ts即為tt轉換成的數字

轉換為浮點數 string.atof(tt)(2)直接int

int(tt)即可。

二、數字轉換成字串

tt=322

tem='%d' %tt

tem即為tt轉換成的字串

8樓:匿名使用者

整數字串轉換為對應的整數int('12')。

使用格式化字串:

tt=322

tem='%d' %tt

tem即為tt轉換成的字串

小數字串轉換為對應小數float('12.34')。

double num1 = 0.0;

string ** = "12.34";

num1 = double.valueof(**.tostring());

數字轉換為字串str(123.45)。

(123.45).to_bytes(4, 'big')

b'\x13\x9b\xe5\x87'

ascii碼轉換為相應字元chr(97)。

字元轉換為響應ascii碼ord('a')。

下面是python中對這幾個方法的簡單說明:ord(...) ord(c) -> integer return the integer ordinal of a one-character string。

chr(...)

chr(i) -> character

return a string of one character with ordinal i; 0 <= i < 256。

repr(...)

repr(object) -> string return the canonical string representation of the object。

for most object types, eval(repr(object)) == object。

unichr(...)

unichr(i) -> unicode character return a unicode string of one character with ordinal i; 0 <= i <= 0x10ffff。

9樓:匿名使用者

#x須為數字,否則把字串型別的字母/漢子/標點符號轉化為int型別毫無意義,會報錯。

x = 1 #x為int型別。

s = str(x) #把x轉換為字串型別,即'x'.

i = int(s) #把字串型別的x轉換為int型別的x。

10樓:藍藍藍

一、python中字串轉換成數字

1、類中進行匯入:import string ,str='555',num=string.atoi(str),num即為str轉換成的數字轉換為浮點數:

string.atof(str)

2、直接intint(str)即可。

二、數字轉換成字串

num=322,str='%d'%num,str即為num轉換成的字串

11樓:淺雨唯一

#!/usr/bin/python

#-*- coding:utf-8 -*-if __name__ == "__main__":

a = '64'

print 'type(a)=', type(a)print 'a=', a

print

b = int(a)

print 'type(b),', type(b)print 'b=', b

print

c = '40'

print 'type(c),', type(c)print 'c=', c

d = int(c, 16)

print 'type(d),', type(d)print 'd=', d

print

e = '100'

print 'type(e),', type(e)print 'e=', e

f = int(e, 8)

print 'type(f),', type(f)print 'f=', f

print

g = '1000000'

print 'type(g),', type(g)print 'g=', g

h = int(g, 2)

print 'type(h),', type(h)print 'h=', h

12樓:匿名使用者

int(str)

float(str)

str(int)

str(float)

13樓:名字都沒一個

將input中的字串轉換為數字:

首先我們知道inpu輸入的內容為字元,如果輸入為『』數字『』要轉換為python中的數字,則要分為整數數值,或小數點數值,可用以下方法:

a=input('請輸入一個數字')

try:

n=int(a)

except:

n=float(a)

另外如果要轉換為其他型別,可以在後面再加except:

int(x [,base ]) 將x轉換為一個整數

long(x [,base ]) 將x轉換為一個長整數

float(x ) 將x轉換到一個浮點數

***plex(real [,imag ]) 建立一個複數

str(x ) 將物件 x 轉換為字串

repr(x ) 將物件 x 轉換為表示式字串

eval(str ) 用來計算在字串中的有效python表示式,並返回一個物件

tuple(s ) 將序列 s 轉換為一個元組

list(s ) 將序列 s 轉換為一個列表

chr(x ) 將一個整數轉換為一個字元

unichr(x ) 將一個整數轉換為unicode字元

ord(x ) 將一個字元轉換為它的整數值

hex(x ) 將一個整數轉換為一個十六進位制字串

oct(x ) 將一個整數轉換為一個八進位制字串

ord: 將ascii字串轉化為ascii值

統計字串中數字字元和字母的個數分別是多少。c程式設計

c的 我改了下 你自己看看 要是還不行 就自己改改 include using namespace std void count char s,int digit,int letter,int other void main 希望對樓主有個小小的幫助。0 9是48 57,a z是65 90,a z是...

winformc文字框用逗號分割字串問題謝謝幫

ordid 012001 or 012003 相當於 orderid in 012001 012003 string str textbox1.text 假定輸入框名為textbox1 去除字串中原本 號,然後將,替換為 然後在前後附加 str str.trim replace replace st...

如何計算c中字串中數字的個數

給你一個思路吧,你可以取去字串裡的字元,一位位用ascii比較是否是數字 include include include using namespace std bool isnumber char ch int main cout t endl return 1 給你這個東西,isdigit c ...