python 程式設計中遇見的錯誤(一)

2021-06-27 11:37:56 字數 769 閱讀 6078

1.臨時變數

x='cdfac'

if 'c' in x:

x.replace('c','')

print x

輸出結果並我不是我們想要得dfc,而仍是cdfac。經過修改:

x='cdfac'

if 'c' in x:

x=x.replace('c','')

print x

達到效果輸出dfa。

分析:在語句塊中對語句塊之外的變數進行修改時,要進行賦值。以免在臨時變數無法儲存。

2.字典的遍歷

dic = 

for item in dic:#遍歷索引

print item

for item in dic:#遍歷字典

print a[item]

3.對字典進行遍歷是刪除字典元素

for i in dic:

if dic[i] <= len(dic)/2:

del dic[i]

不能對遍歷的字典進行刪除操作

4.python中的-1的含義

這是我所見過的兩種-1,前者是索引-1表示list中的最後一項,後者是切片-1表示list的倒數第二項。

接觸pl sql 遇見的錯誤

首先開啟測試視窗 在指令碼中輸入 declare 這裡面定義變數 begin 這裡寫 記住 需要用 結束 end end之後需要乙個 在end 之後需要寫 來結束這一段程式設計 如果列印不出 1.是否使用了在開始時呼叫set severoutput on 例子 sql set serveroutpu...

平時遇見的錯誤集合

問題1 例項化乙個thread並start 之後,等待這個執行緒isalive false 時再次去start 該執行緒時會報如下錯誤 the thread already started 解決方法 每次start 執行緒之前都要重新例項化一次 問題2 使用httpurlconnection.get...

Hibernate 可能遇見的乙個錯誤

exception in thread main org.hibernate.transactionexception transaction not successfully started package com.demo.hibernate.dao import org.hibernate.h...