Python raw_input 函数 - Python零基础入门教程
生活随笔
收集整理的這篇文章主要介紹了
Python raw_input 函数 - Python零基础入门教程
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目錄
- 一.前言
- 二.Python input 和 raw_input 區別
- 1.當輸入為純數字時
- 2.當輸入字符串為表達式
- 三.Python input 函數實現原理
- 四.猜你喜歡
基礎 Python 學習路線推薦 : Python 學習目錄 >> Python 基礎入門
一.前言
Python 2.x 版本中才有內置函數 raw_input 和 input 兩個函數;
Python 3.x 版本中并沒有內置函數 raw_input,如果在 Python 3.x 版本中使用內置函數 raw_input,會提示:NameError: name ‘raw_input’ is not defined
二.Python input 和 raw_input 區別
1.當輸入為純數字時
- ** input 返回的是數值類型,如 int , float**
- ** raw_inpout 返回的是字符串類型,string 類型**
2.當輸入字符串為表達式
Python input 會計算在字符串中的數字表達式,而 raw_input 不會。
如輸入 “57 + 3” : input 會得到整數 60 ;raw_input 會得到字符串 ”57 + 3”;
三.Python input 函數實現原理
看 Python input 文檔,可以看到 input 其實是通過 raw_input 來實現的,原理很簡單,就下面一行代碼:
# !usr/bin/env python # -*- coding:utf-8 _*- """ @Author:猿說編程 @Blog(個人博客地址): www.codersrc.com @File:Python raw_input 函數.py @Time:2021/05/04 07:37 @Motto:不積跬步無以至千里,不積小流無以成江海,程序人生的精彩需要堅持不懈地積累!"""def input(prompt):return (eval(raw_input(prompt)))四.猜你喜歡
未經允許不得轉載:猿說編程 ? Python raw_input 函數
總結
以上是生活随笔為你收集整理的Python raw_input 函数 - Python零基础入门教程的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 沙盒相关简介
- 下一篇: 全网最细之接口的定义与实现