alex

列表的日常操作

雨燕双飞 提交于 2019-12-26 17:46:12
增: .append 追加(默认追加到最后位置) l1 = ['alex', '太白', '吴老师', '景女神', '武大'] l1.append('alex') l1.append(100) l1.append([1, 2, 3]) print(l1) .insert 插入(按下标来选择插入的位置)-->(1,'你妹') .extend 迭代追加(将新添加的内容以仅次于最外层包裹的单位来分开添加) l1 = ['alex', '太白', '吴老师', '景女神', '武大'] l1.insert(1,'小潘') l1.extend('alex') l1.extend(['肖锋', 666]) print(l1) 删: .pop() 按照索引删除,会将删除的元素作为返回值返回 l1 = ['alex', '太白', '吴老师', '景女神', '武大'] ret = l1.pop(0) print(ret) print(l1) .remove()按照元素删除,被删除的元素的返回值为None l1 = ['alex', '太白', '吴老师', '景女神', '武大'] ret = l1.remove('武大') print(ret) print(l1) .clear() 清空列表 del :1,按照索引删除;2,按照切片(加步长)删除;3,删除整个列表 l1 = ['alex',

数据类型之列表

隐身守侯 提交于 2019-12-26 01:28:25
多个装备,多个爱好,多门课程,多个女朋友等 定义:[]内可以有多个任意类型的值,逗号分隔 my_girl_friends=['alex','wupeiqi','yuanhao',4,5] #本质my_girl_friends=list([...]) print(list('hello')) print(int('123')) print(str(123)) 优先掌握的操作: 按索引存取值(正向存取+反向存取):即可存也可以取 my_girl_friends=['alex','wupeiqi','yuanhao',4,5] 切片(顾头不顾尾,步长) 长度 print(my_girl_friends.__len__()) print(len(my_girl_friends)) 成员运算in和not in print('wupeiqi' in my_girl_friends) 追加 my_girl_friends[5]=3 #IndexError: list assignment index out of range my_girl_friends.append(6) print(my_girl_friends) 删除 my_girl_friends=['alex','wupeiqi','yuanhao',4,5] 单纯的删除 del my_girl_friends[0] print

列表类型

早过忘川 提交于 2019-12-26 01:26:29
作用:多个装备,多个爱好,多门课程,多个女朋友等 定义: [] 内可以有多个任意类型的值,逗号分隔 my_girl_friends=['alex','wupeiqi','yuanhao',4,5] # 本质 my_girl_friends=list([...]) l=list('hello') # list 内只能跟能够被 for 循环遍历的数据类型 print(l) l=list({'a':1,'b':2}) print(l) 优先掌握的操作: 1 、按索引存取值 ( 正向存取 + 反向存取 ) :即可存也可以取 names=['alex','wxx','lxx','egon'] names[0]='ALEX' print(names) 2 、切片 ( 顾头不顾尾,步长 ) names=['alex','wxx','lxx','egon'] print(names[0:3]) 3 、长度 names=['alex','wxx','lxx','egon'] print(len(names)) 4 、成员运算 in 和 not in names=['alex','wxx','lxx','egon',4] print(4 in names) 5 、追加 names=['alex','wxx','lxx','egon'] names.append('cxx1') names.append

Using alex/happy with Cabal

£可爱£侵袭症+ 提交于 2019-12-21 07:55:14
问题 I'm writing a compiler for a class I'm taking. The class isn't specifically Haskell but I'm using Haskell to write my compiler and interpreter. I have a cabal package setup to hopefully make it easy for my prof to run/compile. I have happy and alex in the build-tools field for both executables but Cabal ignores that and then complains that it cannot find the modules that Happy and Alex should be generating. If I manually run: alex LimpScanner.x happy LimpParser.y then cabal runs perfectly. I

javaScript的问题

a 夏天 提交于 2019-12-20 04:25:25
js 中的值传递和引用传递 js 函数传参的时候,如果是基本类型,则按值传递,如果是引用类型,则是引用传递(按地址传递) var num = 1 function foo(num) { num = num + 1 return num } foo(num) // 2 num // 1 function changeAgeImpure(person) { person.age = 25; return person; } var alex = { name: "Alex", age: 30 }; var changedAlex = changeAgeImpure(alex); console.log(alex); // { name: 'Alex', age: 25 } console.log(changedAlex); // { name: 'Alex', age: 25 } function changeAgeAndReference(person) { person.age = 25; // 按址传递,会修改对象 // 一个新对象,指向另一个内存地址 person = { name: "John", age: 50 }; return person; } var personObj1 = { name: "Alex", age: 30 }; var personObj2 =

How to Lex, Parse, and Serialize-to-XML Email Messages using Alex and Happy

回眸只為那壹抹淺笑 提交于 2019-12-12 17:17:59
问题 I am working toward being able to input any email message and output an equivalent XML encoding. I am starting small, with one of the email headers -- the "From Header" Here is an example of a From Header: From: John Doe <john@doe.org> I want it transformed into this XML: <From> <Mailbox> <DisplayName>John Doe</DisplayName> <Address>john@doe.org</Address> </Mailbox> </From> I want to use the lexical analyzer "Alex" (http://www.haskell.org/alex/doc/html/) to break apart (tokenize) the From

[af]?lex regular expression difference

陌路散爱 提交于 2019-12-12 06:39:41
问题 I don't know how to do this, and I've found no good resources online for how to perform this operation[.] I'm trying to take an annotated EBNF production rule which is a difference between two regular expressions and turn it into a(n a| f?)lex grammar specification rule[.] The problem is that I see no way to do this normally[.]{3} is there a way to do this using Kleene algebra, like the way you can use an empty match with alternation in a context-free grammar[?] 回答1: What does the EBNF

What causes Happy to throw a parse error?

假如想象 提交于 2019-12-10 11:04:18
问题 I've written a lexer in Alex and I'm trying to hook it up to a parser written in Happy. I'll try my best to summarize my problem without pasting huge chunks of code. I know from my unit tests of my lexer that the string "\x7" is lexed to: [TokenNonPrint '\x7', TokenEOF] My token type (spit out by the lexer), is Token . I've defined lexWrap and alexEOF as described here, which gives me the following header and token declarations: %name parseTokens %tokentype { Token } %lexer { lexWrap } {

Haskell Alex - error in wrapper template

霸气de小男生 提交于 2019-12-06 00:38:00
问题 I'm trying to understand Alex and lexers in general but I'm having trouble to run my lexer. I wrote lexers in "basic" and "posn" wrappers but I couldn't in "monad" wrapper. I think I have to use monad wrapper because I need to collect strings and token positions in input. I also need multiple states. For now I'm trying to run this simple exmaple: { module Main (main) where } %wrapper "monad" $whitespace = [\ \b\t\n\f\v\r] $digit = 0-9 $alpha = [a-zA-Z_] $upper = [A-Z] $lower = [a-z]

封装

走远了吗. 提交于 2019-12-05 07:27:58
class Person: __key=123#私有属性 def __init__(self,name,password): self.name=name self.__password=password#私有属性 def __get_pwd(self): print(self.__dict__) return self.__password#只要类的内部调用私有属性,就会自动带上_类名 def login(self): self.__password()alex=Person("xiaowang","xiaowang123")print(alex._Person__password)#_类名__属性名print(alex.get_pwd())alex.__high=1print(alex.__high)#私有属性只能在类的内部去设置,在外部就不行#所有的私有都是在变量的左边加上双下划线#所有的私有只能在类的内部使用,不能在外部使用#类的私有方法#类的私有属性#类中的静态私有属性 来源: https://www.cnblogs.com/648071634com/p/11913731.html