{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ff286b11",
   "metadata": {},
   "outputs": [],
   "source": [
    "text = \"petrichor\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "34cdbae1",
   "metadata": {},
   "outputs": [],
   "source": [
    "type(text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5a15c9c0",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Η dir() επιστρέφει όλες τις ιδιότητες και τις μεθόδους ενός αντικειμένου\n",
    "dir(text)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8a221427",
   "metadata": {},
   "source": [
    "Επιτρεπτές πράξεις με str"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "622e7e89",
   "metadata": {},
   "outputs": [],
   "source": [
    "test1 = text*2\n",
    "print(test1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "12c4e2ae",
   "metadata": {},
   "outputs": [],
   "source": [
    "newText = 'I like'\n",
    "test2 =  newText + \" \" + text\n",
    "print(test2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9ff78822",
   "metadata": {},
   "outputs": [],
   "source": [
    "text == \"mythos\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e0499afa",
   "metadata": {},
   "source": [
    "Συναρτήσεις"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2196ccbf",
   "metadata": {},
   "outputs": [],
   "source": [
    "print(f'{text} has {len(text)} characters')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "08edaf42",
   "metadata": {},
   "outputs": [],
   "source": [
    "len(test2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6b6ad486",
   "metadata": {},
   "outputs": [],
   "source": [
    "str(5.2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3378f5c0",
   "metadata": {},
   "source": [
    "Παραδείγματα"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c52d8500",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Η επανάληψη των str επιτρέπεται μόνο όταν ο αριθμός είναι int\n",
    "text * 5.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "48ed8eca",
   "metadata": {},
   "outputs": [],
   "source": [
    "text * int(5.5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "13ca0e9e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Επιτρέπονται μόνο οι πράξεις μεταξύ συμβολοσειρών\n",
    "text + 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8c340ac8",
   "metadata": {},
   "outputs": [],
   "source": [
    "text + str(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dabaf9e8",
   "metadata": {},
   "outputs": [],
   "source": [
    "type(len(text))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "55cd1a73",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = \"b\"\n",
    "b = \"c\"\n",
    "c = \"**\"\n",
    "print(b + a + 2*c)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "000706b8",
   "metadata": {},
   "source": [
    "Indexing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2125a5a4",
   "metadata": {},
   "outputs": [],
   "source": [
    "s = \"car\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "128ba1bb",
   "metadata": {},
   "outputs": [],
   "source": [
    "print(s[0])\n",
    "print(s[1])\n",
    "print(s[2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e50a63df",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Προσοχή στο indexing\n",
    "print(s[3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a47dff91",
   "metadata": {},
   "outputs": [],
   "source": [
    "print(s[-1])\n",
    "print(s[-2])\n",
    "print(s[-3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "75d63374",
   "metadata": {},
   "outputs": [],
   "source": [
    "text[0:len(text)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e1d3bcc4",
   "metadata": {},
   "outputs": [],
   "source": [
    "text[4:9]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a103a423",
   "metadata": {},
   "outputs": [],
   "source": [
    "text[4:9:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "afe7f209",
   "metadata": {},
   "outputs": [],
   "source": [
    "text[:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "00cdc57f",
   "metadata": {},
   "outputs": [],
   "source": [
    "text[::-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "711cf32d",
   "metadata": {},
   "outputs": [],
   "source": [
    "text[4::-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c7ae2e8e",
   "metadata": {},
   "outputs": [],
   "source": [
    "text[0:5:3]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7ce7c3fe",
   "metadata": {},
   "source": [
    "Παραδείγματα επιλογής χαρακτήρων από str"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f188995a",
   "metadata": {},
   "outputs": [],
   "source": [
    "st1 = 'mythos'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "968e8c0d",
   "metadata": {},
   "outputs": [],
   "source": [
    "st1[-1:-4:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3e6cb57d",
   "metadata": {},
   "outputs": [],
   "source": [
    "st1[-1:-4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "51b61fd6",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Προσοχή στο indexing!\n",
    "st1[len(st1)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "649675ef",
   "metadata": {},
   "outputs": [],
   "source": [
    "st1[len(st1)-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cf4b8c32",
   "metadata": {},
   "outputs": [],
   "source": [
    "st2 = \"I'll be back\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ceeb7f43",
   "metadata": {},
   "outputs": [],
   "source": [
    "st2[1:6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e2e52332",
   "metadata": {},
   "outputs": [],
   "source": [
    "st2[-5:-10:3]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "08f648a7",
   "metadata": {},
   "source": [
    "Loop over strings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "47728473",
   "metadata": {},
   "outputs": [],
   "source": [
    "# How many \"w\"'s and \"g\"'s exist in the sentence?\n",
    "song = \"while my guitar gently weeps\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4af4ae44",
   "metadata": {},
   "outputs": [],
   "source": [
    "w_g1 = 0\n",
    "for idx in range(len(song)):\n",
    "    if song[idx] == 'w' or song[idx] == 'g':\n",
    "        w_g1 += 1\n",
    "print(w_g1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "36606b13",
   "metadata": {},
   "outputs": [],
   "source": [
    "w_g2 = 0\n",
    "for chr in song:\n",
    "    if chr == 'w' or chr == 'g':\n",
    "        w_g2 += 1\n",
    "print(w_g2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ee0a13c5",
   "metadata": {},
   "source": [
    "Άσκηση"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d9632b5d",
   "metadata": {},
   "outputs": [],
   "source": [
    "#Σας δίνεται μια συμβολοσειρά (test) με πεζούς χαρακτήρες. Δημιουργήστε μια νέα συμβολοσειρά που διατηρεί μόνο την πρώτη εμφάνιση κάθε γράμματος του test, με τη σειρά που εμφανίζονται.\n",
    "#Π.χ. αν test = ‘tomorrow’ ο κώδικας θα τυπώνει: tomrw\n",
    "#Προσπελάστε διαδοχικά τους χαρακτήρες του test\n",
    "#Καταγράψτε αυτούς που έχετε δει σε μια μεταβλητή συμβολοσειράς (seen)\n",
    "#Εάν ένας χαρακτήρας δεν υπάρχει ήδη στη μεταβλητή seen, προσθέστε τον σε αυτή\n",
    "#Τυπώστε τη συμβολοσειρά seen στο τέλος\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "94c0489b",
   "metadata": {},
   "outputs": [],
   "source": [
    "test = input('Give me a word: ')\n",
    "\n",
    "seen = ''\n",
    "for chr in test: # for not (chr in seen)\n",
    "    if chr not in seen:\n",
    "        seen +=chr # seen = seen + chr\n",
    "print(seen)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
