Python Interview Questions: A Review

2023-11-04

本文转载至:https://www.udemy.com/blog/python-interview-questions/

Python is an elegant and versatile language, used for a wide variety of applications on the Internet and in many kinds of software. Knowing this language can open many doors and career opportunities, so let’s get right to some examples of interview questions you can expect to be presented with, and some possible answers.

Begin your programming adventure with Python with this online tutorial.

Sample Python Interview Questions:

Q:  How are global and local variables defined in Python?

In general, variables that are defined outside of functions are global.  Variables defined inside a function can also be made global, by using the command ‘global x’, for example, to create a global variable called ‘x’.

Q:  Name and describe some common default modules included in Python.

  • email – used to parse, handle, and generate email messages.
  • string – an index of types of strings, such as all capital or lowercase letters.
  • sqlite3 – used to deal with the SQLite database.
  • xml – provides XML support.
  • logging – creates logging classes to log system details.
  • traceback – allows you to extract and print stack trace details.

Q:  Describe the difference between a list and a tuple.

A list can be changed by internal operations.  A tuple cannot be changed; it can only be operated on.  Different methods are used for each.

Q:  Write a sample program to print the complete contents of a file, with a way to catch a missing file.

try:

with open(‘filename’,’r’) as file:

print file.read()

except IOError:

print “no such file exists”

Q:  What is a negative index in Python?

While positive indices begin with position 0 and follow with 1, 2, etc., negative indices end with -1.  -2; -3 is the position before that, and so on.

Q:  Write a sample program to print the sum of all numbers from 25 to 75, inclusive.

print sum(range(25,75))

Q:  Write a sample program to print the length of each line in a particular file, not counting whitespace at the ends.

with open(“filename.txt”, “r”) as file:

print len(file.readline().rstrip())

Learn web programming with Python with this Udemy online class.

Q:  Write a sample program to remove the whitespace from the following string – ‘abc def geh ijk’.

s = ‘abc def geh ijk’

”.join(s.split())

Q:  Write a sample program to remove duplicate items from a given list.

This process is made easier by first sorting and scanning the list:

if List:

List.sort()

last = List[-1]

for i in range(len(List)-2, -1, -1):

if last==List[i]: del List[i]

else: last=List[i]

Q:  How would you store a list of employee first and last names?

A list of first and last names is best stored as a list of dictionaries, in the format: {‘first_name':’Example’,’last_name':’Goel’}

Q:  What is pickling and what is unpickling?

Pickling is a process by which a Python object is converted into a string representation by a pickle module.  It is then placed into a file with the dump() function.  Unpickling refers to the reverse process, in which the stored string is retrieved and turned back into an object.

Q:  Describe a few ways to generate a random number in Python.

  1. random() – this command returns a floating point number, between 0 and 1.
  2. uniform(x,y) – this command returns a floating point number between the values given for x and y.
  3. randint(x,y) – this command returns a random integer between the values given for x and y.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Python Interview Questions: A Review 的相关文章

  • ifstream 和 ofstream 文件中读取和写入操作

    导读 ofstream是从内存到硬盘 ifstream是从硬盘到内存 其实所谓的流缓冲就是内存空间 在C 中 有一个stream这个类 所有的I O都以这个 流 类为基础的 包括我们要认识的文件I O stream这个类有两个重要的运算符
  • BAT脚本一键启动多个程序

    最近写代码 开机要开各种环境 IDE 每次都要对着桌面图标一个个点击 感觉非常麻烦 简直浪费生命 每天开机要花好几分钟打开这些东西 于是稍微学习了一下window下的bat脚本语言 写了一个极为简单而又实用的小脚本 一键将我需要的程序打开
  • Shell 编程:探索 Shell 的基本概念与用法

    目录 Shell 简介 Shell 脚本 Shell 脚本运行 Shell 变量 1 创建变量和赋值 2 引用变量 3 修改变量的值 4 只读变量 5 删除变量 6 环境变量 Shell 字符串操作 1 拼接字符串 2 字符串长度 3 字符
  • java 读取文件 和 执行SQL脚本 (支持中文)

    读文件操作应用 执行SQL脚本文件 执行SQL脚本文件 param path throws SQLException throws ClassNotFoundException public void exeSQLScript String
  • Visual Stdio调试IDAPython脚本

    1 安装VS插件PTVS 这一步与第2步中安装版本应该一致 否则最后调试时会连不上 https github com Microsoft PTVS 2 安装python模块PTVSD pip install ptvsd 3 写如下代码ptv
  • dos命令弹出对话框---Msg命令详解

    dos命令弹出对话框 Msg命令详解 cmd下执行 在当前用户的桌面弹出一个对话框 显示哈哈二字 并且十秒后自动关闭 usename 是系统环境变量 表当前用户名 msg username time 10 哈哈 表示向局域网中的192 16
  • UBOOT命令总结(转)

    UBOOT命令总结 转 很好的UBOOT命令总结 我在起步时就是看的这篇东西 熟悉了以后就用 看自带帮助就行 Printenv 打印环境变量 Uboot gt printenvbaudrate 115200ipaddr 192 168 1
  • window重启Nginx的BAT脚本

    1 脚本入参 SET NGINX DIR C Zone nginx 1 21 4 nginx 1 21 4 该路径配置成nginx的根目录文件夹 2 Nginx管理脚本 echo off chcp 65001 color 0a rem 当前
  • js光标事件

    JavaScript是基于对象 object based的语言 而基于对象的基本特征 就是采用事件驱动 event driven 它是在图形界面的环境下 使得一切输入变化简单化 通常鼠标或热键的动作我们称之为事件 Event 而由鼠标或热键
  • Nmap扫描原理与用法

    Nmap扫描原理与用法 2012年6月16日 1 Nmap介绍 Nmap扫描原理与用法PDF 下载地址 Nmap是一款开源免费的网络发现 Network Discovery 和安全审计 Security Auditing 工具 软件名字Nm
  • 开源软件大集合

    http a note sourceforge net A Note 4 2 1 可在Windows桌面放置便笺 并可提供闹钟提醒功能 http www xs4all nl edienskeAbakt 0 9 能够以压缩方式对文档进行备份
  • 去除快捷方式箭头BAT脚本

    去除快捷方式箭头BAT脚本 1 脚本功能 去除window电脑桌面图标右下角的快捷方式小箭头 对于强迫症患者绝对是福音 总之清除了之后非常的舒畅 2 脚本内容 echo off color 2 reg delete HKCR lnkfile
  • webpack 插件之Html-Webpack-Plugin

    webpack 插件之Html Webpack Plugin 1 为什么我们需要这个插件 先来看一个应用场景 我们自己打算搭建一个网站 这个网站有很多个页面 我们为每个页面创建一大堆的css样式 js脚本 然后尝试用webpack进行打包
  • Windows脚本对最后修改时间超过24小时的文件进行处理

    这次我接到一个任务 是写一个windows上运行的脚本 讲某个文件夹下最后修改时间超过24小时的文件移到另一个文件夹 然后在判断有生成的文件超过十分钟的关闭一个程序再启动它 上网搜了一下 有很多相关的 比如说把最后修改时间的文件超过一天的删
  • abc300.com站点被注入脚本

    在进行abc300 com的页面SEO时发现 所有页面受到注入攻击 全部asp页最后被添加一页 弄了1个多小时 大部份页面被清除 目前已经获得www hulijie com的ftp 222 33 63 206 用户名admin 密码尚需分析
  • cookie格式化

    字符串转成字典 使用场景 selenium尝试试用cookie登陆时 Network中cookie是一段字符串 需要转成字典使用 使用split和列表解析式 str thor 8954F43 Id d32def3ffSNw pn adsad
  • 关于UI适配的文档

    第一部分 原理 1 根据当前屏幕尺寸与开发预设屏幕尺寸尺寸得出以下参数 1 XRatio 当前屏幕尺寸与开发尺寸的X轴比例 2 YRtaio 当前屏幕尺寸与开发尺寸的Y轴比例 3minRatio XRatio与YRtaio中的较小值 2 之
  • 操作系统常见面试题

    1 什么是进程 Process 和线程 Thread 有何区别 进程是具有一定独立功能的程序关于某个数据集合上的一次运行活动 进程是系统进行资源分配和调度的一个独立单位 线程是进程的一个实体 是CPU调度和分派的基本单位 它是比进程更小的能
  • 设置bat工作目录

    在执行bat脚本的时候 如果直接双击bat脚本 此时的工作路径一般为 C Users Administrator gt 很多时候需要将工作路径设置为bat脚本所在的目录 可以在bat脚本内设置当前工作路径为bat文件所在目录 cd d dp
  • 将指定文件夹中的图片文件复制到另一个文件夹,并按照自然数递增的命名规则重命名的程序

    文件目录结构 C data photos 1 2 3 4 5 6 7 8 photos new 1 2 3 4 5 6 7

随机推荐

  • Kafka集群的搭建以及java生产消费代码测试

    1 什么是Kafka 官网上 Kafka 用于构建实时数据管道和流式应用程序 它具有横向可扩展性 容错性 速度极快 在数千家公司的生产中运行 2 集群搭建准备 JDK Zookeeper集群 https blog csdn net qq 3
  • LDO原理简析

    LDO是低压差稳压器 并且是线性稳压器 只能用在降压的场景下 即输出电压只能比输入电压小 优点是负载响应快 并且十分稳定 纹波也比较小 缺点是输入电压和输出电压不能相差过大 负载也不能太大 并且效率较低 线性调节意谓着输入输出的电压差乘上平
  • Unity3D启动时卡在Loading界面

    首先说说我是怎么遇到这个问题的吧 当初是因为手贱无意中点了这个Sign out 退出当前用户 然后就一直卡在Loading界面死循环了 收集了一些网上的解决方法都不好使 难道是因为我是Mac系统的Unity 解决方案 一 Windows系统
  • 【待完善】python中调用 imread 报错: ImportError: cannot import name imread

    pip install Pillow 该问题排查有以下几种情况 未安装 Pillow库 scipy版本不对 ImportError cannot import name imread from scipy misc 是由于 imread i
  • 生成ltx文件命令_系统小技巧:实用简单的PowerShell命令

    从Windows 10 1703版开始 PowerShell取代了原命令提示符的位置 成为Windows管理的必备利器 然而许多普通Windows用户不知它的用途 其实 通过在PowerShell窗口中执行简单的命令 往往可以解决一些实际问
  • 2023/9/11 qt&c++

    include
  • LeetCode646.最长数对链

    题目描述 646 最长数对链 力扣 LeetCode 这是一道典型的贪心算法题 我们先对原数对进行排序 排序规则是按照数对的右边界值的大小进行升序排列 初始化变量end为升序后第一个数对的右边界值 这个数无疑是最小的右边界 之后依次遍历整个
  • Qt程序的打包和发布(使用windeployqt)

    将编写完成的Qt程序进行打包 使得没有安装Qt环境的电脑也可以运行编写完成的应用 1 Release文件生成 在Qt Creator中 将构建方式改为Release 点击运行 或ctrl r快捷键运行 2 找到exe文件 复制到一个空目录中
  • java单元测试之Mock静态方法

    用例子说明 例如有下面静态方法 public final class AmountUtil public static String CustomFormatWith2Digits int amount return 1 单元测试代码 需要
  • 服务器端虚拟化安卓,安卓服务器端实例

    安卓服务器端实例 内容精选 换一换 本章节以Linux操作系统为例 指导您通过内网IP的方式连接GaussDB for Redis 实例 目标实例必须与弹性云服务器在同一个虚拟私有云和子网内才能访问 弹性云服务器必须处于目标实例所属安全组允
  • vscode和vs有什么区别?

    vscode是微软新推出的一款代码编辑器 内置了一些编译器 免费开源跨平台的工具 VS是微软的商业企业级开发环境IDE 在这之前 我们写代码的工具可以分为三个层次 最轻量级的叫做代码编辑器 例如notepad notepad subline
  • OD查看字符串

    在反汇编窗口中右击 出来一个菜单 我们在 查找 gt 所有参考文本字串 上左键点击 在text string窗口后 再右击这个窗口里面随便一处 选 search for text 输入要查找的内容 把Case sensitive 区分大小写
  • 【RoCE】拥塞控制机制(ECN, DC-QCN)

    1 网络拥塞问题 在网络交换机中 当入口流量大于出口流量的带宽时会发生网络拥塞 典型的例子是多个发送方同时向同一个目的地发送网络数据 交换机的缓存可以处理暂时的拥塞 但是当拥塞太久时 交换机的缓存就会过载 当交换机缓存过载时 下一个收到的新
  • mysql ipk 编译_OpenWrt的ipk包安装

    在 make menuconfig 进行裁减 OpenWrt 时 为了让系统更精小一点 我们会把部分功能以 模块 的方式编译 即不编入内核 只是在后期用户可以进行安装与卸载 包安装示例 如下关于Lua的配置项 其中 json4lua lua
  • 头文件库文件

    问题 不知道 Visual Studio 的头文件库文件如何配置 方法 C C gt 常规 gt 附加包含目录 添加头文件 链接器 gt 常规 gt 附加库目录 添加库目录 链接器 gt 输入 gt 附加依赖项 添加库文件
  • zip文件解压详解

    文章目录 1 起因 2 详解 3 实践 4 参考 1 起因 自己之前在linux系统解压zip文件 一直用 unzip zip 我们期望解压后的文件都是统一放到以 命名的文件夹下 但是自己有一次解压后发现所有的文件并没有放到上述文件夹下 而
  • 使用 @RequestMapping 注解,需要导入的包:spring-webmvc

    在Controller 层使用 RequestMapping注解 需要导入的包 spring webmvc 在类中需要添加 import org springframework web bind annotation RequestMapp
  • Pycharm激活方法使用的是(license server)Activate new license with: License server

    pycharm所有版本 http www jetbrains com pycharm download previous html 打开激活窗口 选择 Activate new license with License server 用li
  • 【JVM调优】JDK11-JVM基本参数调优以及日志打印

    Parm Xmx2g Xms1g Xss256k XX MaxDirectMemorySize 256m XX UseG1GC XX UseCompressedOops XX UseCompressedClassPointers XX Se
  • Python Interview Questions: A Review

    本文转载至 https www udemy com blog python interview questions Python is an elegant and versatile language used for a wide va