Recent Changes - Search:

Oktatás

* Programozás 1
  + feladatsor
  + GitHub oldal

* Szkriptnyelvek
  + feladatsor
  + quick link

Teaching

* Programming 1 (BI)
  ◇ exercises
  ◇ quick link

* Scripting Languages
  ◇ exercises
  ◇ quick link

teaching assets


Félévek

* aktuális (2023/24/2)
* archívum


Linkek

* kalendárium
   - munkaszüneti napok '20
* tételsorok
* jegyzetek
* szakdolgozat / PhD
* ösztöndíjak
* certificates
* C lang.
* C++
* C#
* Clojure
* D lang.
* Java
* Nim
* Scala


[ edit | logout ]
[ sandbox | passwd ]

some string operations

#############################

Python slices

Python Scala
>>> s = "hello python and scala"
>>> s
'hello python and scala'

>>> s[0]
'h'

>>> s[-1]
'a'




>>> s[:2]
'he'

>>> s[-2:]
'la'

>>> s[6:12]
'python'

>>> len(s)
22

>>> s[::-1]
'alacs dna nohtyp olleh'

>>> s[2:]
'llo python and scala'

>>> s[:-2]
'hello python and sca'

>>> s[1:]
'ello python and scala'
scala> val s = "hello python and scala"
s: String = hello python and scala


scala> s(0)    // or: s.head
res0: Char = h

scala> s.last
res3: Char = a    // as char

scala> s.takeRight(1)
res5: String = a    // as string

scala> s.take(2)
res6: String = he

scala> s.takeRight(2)
res7: String = la

scala> s.substring(6, 12)
res11: String = python

scala> s.length
res12: Int = 22

scala> s.reverse
res14: String = alacs dna nohtyp olleh

scala> s.drop(2)
res18: String = llo python and scala

scala> s.dropRight(2)
res22: String = hello python and sca

scala> s.tail
res23: String = ello python and scala

More…

Python Scala
>>> "ke" in "joker"
True

>>> "joker".find("ke")    // -1 if not found
2
scala> "joker" contains "ke"
res125: Boolean = true

scala> "joker".indexOf("ke")    // -1 if not found
res126: Int = 2
Cloud City

  

Blogjaim, hobbi projektjeim

* The Ubuntu Incident
* Python Adventures
* @GitHub
* heroku
* extra
* haladó Python
* YouTube listák


Debrecen | la France


[ edit ]

Edit - History - Print *** Report - Recent Changes - Search
Page last modified on 2015 March 15, 08:35