1. 程式人生 > >Python3 與 NetCore 基礎語法對比(List、Tuple、Dict、Set專欄)

Python3 與 NetCore 基礎語法對比(List、Tuple、Dict、Set專欄)

// using System;
// using System.Collections.Generic;
// using System.Linq;

// namespace aibaseConsole
// {
//     public static class Program
//     {
//         private static void Main()
//         {
//             #region List
//             //# 定義一個列表
//             // # infos_list=["C#","JavaScript"]#[]
//             var infos_list = new List<object>() { "C#", "JavaScript" };
// // var infos_list2 = new List<object>() { "張三", 21 }; // // // # ########################################################### // // // # # 遍歷 for while // // // # for item in infos_list: // // // # print(item) // // foreach (var item in infos_list)
// // { // // System.Console.WriteLine(item); // // } // // for (int i = 0; i < infos_list.Count; i++) // // { // // System.Console.WriteLine(infos_list[i]); // // } // // // # i=0 // // // # while i<len(infos_list):
// // // # print(infos_list[i]) // // // # i+=1 // // int j=0; // // while(j<infos_list.Count){ // // Console.WriteLine(infos_list[j++]); // // } // // // # ########################################################### // // // # # 增加 // // // # # 末尾追加 // // // # infos_list.append("Java") // // // # print(infos_list) // // DivPrintList(infos_list); // // infos_list.Add("Java"); // // DivPrintList(infos_list); // // // # # 指定位置插入 // // // # infos_list.insert(0,"Python") // // // # print(infos_list) // // infos_list.Insert(0,"Python"); // // DivPrintList(infos_list); // // // # # 新增一個列表 // // // # infos_list2=["張三",21]#python裡面的列表類似於List<object> // // // # infos_list.extend(infos_list2) // // // # print(infos_list) // // infos_list.AddRange(infos_list2); // // DivPrintList(infos_list); // // /*C#有insertRange方法 */ // // DivPrintList(infos_list2,"List2原來的列表:"); // // infos_list2.InsertRange(0,infos_list); // // DivPrintList(infos_list2,"List2變化後列表:"); // // // # # help(infos_list.extend)#可以檢視etend方法描述 // // // # ########################################################### // // // # # 刪除 // // // # # pop()刪除最後一個元素,返回刪掉的元素 // // // # # pop(index) 刪除指定下標元素 // // // # print(infos_list.pop()) // // // # print(infos_list) // // // # print(infos_list.pop(1)) // // // # # print(infos_list.pop(10)) #不存在就報錯 // // // # print(infos_list) // // // # # remove("")刪除指定元素 // // // # infos_list.remove("張三") // // // # # infos_list.remove("dnt") #不存在就報錯 // // // # print(infos_list) // // // # # del xxx[index] 刪除指定下標元素 // // // # del infos_list[1] // // // # print(infos_list) // // // # # del infos_list[10] #不存在就報錯 // // // # del infos_list #刪除集合(集合再訪問就不存在了) // // DivPrintList(infos_list); // // infos_list.RemoveAt(1); // // // infos_list.RemoveAt(10);//不存在則報錯 // // // infos_list.RemoveRange(0,1); //可以移除多個 // // DivPrintList(infos_list); // // infos_list.Remove("我家在東北嗎?"); //移除指定item,不存在不會報錯 // // DivPrintList(infos_list,"清空前:"); // // infos_list.Clear();//清空列表 // // DivPrintList(infos_list,"清空後:"); // // // # ########################################################### // // // # # 修改 xxx[index]=xx // // // # # 注意:一般不推薦在for迴圈裡面修改 // // // # print(infos_list2) // // // # infos_list2[1]="PHP" #只有下標修改一種方式 // // // # # infos_list2[3]="GO" #不存在則異常 // // // # print(infos_list2) // // DivPrintList(infos_list2); // // infos_list2[1] = "PHP"; // // // infos_list2[3]="GO"; //不存在則異常 // // DivPrintList(infos_list2); // // // # # 想按值修改需要先查下標再修改 // // // # infos_list2.index("張三") // // // # infos_list2[0]="GO" // // // # print(infos_list2) // // // # # infos_list2.index("dnt")#不存在則異常 // // int index = infos_list2.IndexOf("張三"); // // infos_list2[index] = "GO"; // // DivPrintList(infos_list2); // // infos_list2.IndexOf("dnt");//不存在返回-1 // // // ########################################################### // // // # 查詢 in, not in, index, count // // // # # for擴充套件:https://www.cnblogs.com/dotnetcrazy/p/9102030.html#forelse // // // # names_list=["張三","李四","王二麻子"] // // var names_list=new List<string>(){"張三","李四","王二麻子"}; // // // Console.WriteLine(names_list.Find(i=>i=="張三")); // // // Console.WriteLine(names_list.FirstOrDefault(i=>i=="張三")); // // Console.WriteLine(names_list.Exists(i=>i=="張三")); // // System.Console.WriteLine(names_list.Contains("張三")); // // // # #張三在列表中執行操作 // // // # if "張三" in names_list: // // // # names_list.remove("張三") // // // # else: // // // # print(names_list) // // // # #檢視"大舅子"不在列表中執行操作 // // // # if "大舅子" not in names_list: // // // # names_list.append("大舅子") // // // # else: // // // # print(names_list) // // // # #查詢王二麻子的索引 // // // # print(names_list.index("王二麻子")) // // // names_list.IndexOf("王二麻子"); // // // # print(names_list.count("大舅子")) // // // # print(names_list.count("逆天")) // // // Console.WriteLine(names_list.Count); // // // ########################################################### // // // # # 排序(sort, reverse 逆置) // // // # num_list=[1,3,5,88,7] // // var num_list = new List<object>() { 1, 3, 5, 88, 7 }; // // // # #倒序 // // // # num_list.reverse() // // // # print(num_list) // // num_list.Reverse(); // // DivPrintList(num_list); // // // # # 從小到大排序 // // // # num_list.sort() // // // # print(num_list) // // num_list.Sort(); // // DivPrintList(num_list); // // // # # 從大到小 // // // # num_list.sort(reverse=True) // // // # print(num_list) // // num_list.Sort(); // // num_list.Reverse(); // // DivPrintList(num_list); // // // # ########################################################### // // // # #列表巢狀(列表也是可以巢狀的) // // // # num_list2=[33,44,22] // // // # num_list.append(num_list2) // // // # print(num_list) // // var num_list2 = new List<object>() { 33, 44, 22,new List<object>(){11,55,77} }; // // DivPrintList(num_list2);//可以定義多維陣列來支援 num_list2[i][j] // // // # for item in num_list: // // // # print(item) // // // # ########################################################### // // // # # 引入Null==>None // // // # a=[1,2,3,4] // // // # b=[5,6] // // // # a=a.append(b)#a.append(b)沒有返回值 // // // # print(a)#None // #endregion // // Console.Read(); // } // private static void DivPrintList(List<object> list, string say = "") // { // Console.WriteLine($"\n{say}"); // foreach (var item in list) // { // System.Console.Write($"{item} "); // } // } // } // }

相關推薦

Python3 NetCore 基礎語法對比ListTupleDictSet專欄

// using System; // using System.Collections.Generic; // using System.Linq; // namespace aibaseConsole // { // public static class Program //

Python3 C# 基礎語法對比ListTupleDictSet專欄

Help on class set in module builtins: class set(object) | set() -> new empty set object | set(iterable) -> new set object | | Build

Python3 NetCore 基礎語法對比就當Python和C#基礎的普及吧

歡迎提出更簡單的語法~(文章中案例有兩個福利哦,一個是養生,一個是人工智慧[ 密碼:fqif]) 先說下感覺,python的程式設計有點JavaScript的感覺(比如:'和“有時候不區別),又感覺像外國版的易語言,整個過程像讀書一樣,比如一個元素不在列表之中==> for ite

Python3 NetCore 基礎語法對比String專欄

using System; using System.Linq; namespace aibaseConsole { public static class Program { private static void Main() {

Python3 NetCore 基礎語法對比Function專欄

using System; using System.Collections.Generic; namespace _6func { class Program { static void Main(string[] args) {

Python3 C# 基礎語法對比String專欄

using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; public static partial class ValidationHelp

Python3 C# 基礎語法對比Function專欄

主要是普及一下Python基礎語法,對比著Net,新手更容易上手。 對比學習很有意思的,尤其是一些底層和思路 本來感覺函式要說的地方沒多少,細細一規劃,發現~還是單獨拉出一篇說說吧 之後就進入面向物件了,函式還是有必要了解一下的,不然到時候Class裡面的方法定義又要說了。 演示的

Python3 C# 基礎語法對比就當Python和C#基礎的普及吧

['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global'

python初級資料結構listtupledict補充筆記,初級

List: 遞推式構造列表(List Comprehension),例: list = [x*2 for x in lm] 切片list[start: stop: step] sort 和 sorted: sort會改變list(in-place),而sorted返回排序好的列表(retu

listtupledictset的主要區別

1 .list list是一個使用方括號括起來的有序元素集合; List 可以作為以 0 下標開始的陣列,任何一個非空 list 的第一個元素總是 L[0],負數索引從 list 的尾部開始向前計數來存取元素。任何一個非空的 list 最後一個元素總是 L[-1]; 有

python 容器特點總結:listtupledictset

list:有序的,可重複的,可以儲存任何型別,可改變 tuple:有序的,不可變,可重複,可以儲存任何型別 set:無序的,可變,不可重複,(用於去重),可以儲存任何型別 dict:值鍵對, 無序的, 鍵不可重複,值可重複,鍵不可變,值可變,可以儲存任何型別

python中listtupledictset的區別及聯絡

我在python學習中遇到的一個與其他語言不太相同的一點就是list.tuple.dict.set這幾個資料型別的區別及聯絡。昨天學了,為防忘記,今天就來現學現賣。 一、list          俗稱列表,是一種有序集合。也就是說,list中的資料排列是有順序的。可以

css基礎語法選擇器css導入方式

數字 mic link html clas ref height font 兼容 頁面中,所有的CSS代碼,需要寫入到<style></style>標簽中。style標簽的type屬性應該選擇text/css,但是type屬性可以省略。 CS

python基礎語法總結-- python類OOP面向物件特性

python常用系統函式方法與模組 python基礎語法總結(一)-- python型別轉換函式+檔案讀寫 python基礎語法總結(二)-- 函式function python基礎語法總結(三)-- 數與字串 python基礎語法總結(四)-- list列表

python基礎語法總結-- list列表

python常用系統函式方法與模組 python基礎語法總結(一)-- python型別轉換函式+檔案讀寫 python基礎語法總結(二)-- 函式function python基礎語法總結(三)-- 數與字串 python基礎語法總結(四)-- list列表

python基礎語法總結-- 數字串

python常用系統函式方法與模組 python基礎語法總結(一)-- python型別轉換函式+檔案讀寫 python基礎語法總結(二)-- 函式function python基礎語法總結(三)-- 數與字串 python基礎語法總結(四)-- list列表

python3第一天(基礎語法)

python3基礎語法對於python3的應用程序,解釋器用/usr/bin/python3(python3如果不在此目錄下,更換到相應目錄).對於運行,可以對寫的腳本添加執行權限,也可以用指定的程序來執行(如:python3 ./腳本)默認情況下,Python3的源碼文件都是utf-8編碼,所有的字符串都是

課後筆記一:Python基礎語法介紹1

Python3.6.5我們總是找借口說還有時間去做某事,或者完成某事,結果總是不了了之。比如拖到現在才寫第一課聽課筆記。 第一節課,老師對以下內容做了分享,大致分為 環境配置 開發平臺:Mac OS Version 10.13.2 老師講課的是在Windows 10 我選擇在Mac OS進行Pyth

Python3 教程 - 001 基礎語法

Python3 基礎語法 編碼 預設情況下,Python 3 原始碼檔案以 UTF-8 編碼,所有字串都是 unicode 字串。當然你也可以為原始碼檔案指定不同的編碼: # -*- coding: cp-1252 -*- 上述定義允許在原始檔中使用 Windows-1252 字符集中的

手繪碼繪的對比靜態

在這次對比用程式碼和用手繪創作靜態繪畫的實驗中,選擇的程式設計工具是p5.js,p5.js語法和使用上較為簡單,入門很快,繪製的作品為一個簡單的卡通小黃人。下面按要求從思路、技術、創作體驗、創作偏好等方面比較一下二者,以及它們的異同。 碼繪程式碼如下: function setup()